Page 1 of 4 1234 LastLast
Results 1 to 10 of 34
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default [PHP/mySQL] Question

    When selecting a database using mysql_select_db(), can you use the function more than once and still retain the previous database selection? For example, can I do:

    mysql_select_db('abc');
    mysql_select_db('def');

    Would that select both databases or would it select abc then select def?
    Vouches
    [x][x]

  2. #2
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    I believe you would need two instances of a mysql connection active in order to connect to two databases simultaneously.
    Hi, names James. I am a web developer.

  3. #3
    Join Date
    Apr 2008
    Location
    Derby
    Posts
    4,668
    Tokens
    262

    Latest Awards:

    Default

    Ya know what i'd do, have 2 config files and have

    include ('config.php');
    include ('config2.php');

    Lol
    Dunn of it would work though
    Back for a while

  4. #4
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    When selecting a database using mysql_select_db(), can you use the function more than once and still retain the previous database selection? For example, can I do:

    mysql_select_db('abc');
    mysql_select_db('def');

    Would that select both databases or would it select abc then select def?
    abc then def, if you wanted only 1 mysql connection, you could do it with a bit of overhead, you have 2 functions, i.e "mysql_select_2" "mysql_select_1" and you put this in each:

    PHP Code:
    mysql_query('USE `databasename`'); 
    then run the query.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  5. #5
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    So wouldn't I just be better off doing something like:

    mysql_query('USE db1 SELECT * blah blah blah');
    and
    mysql_query('USE db2 SELECT * blah blah blah');
    Vouches
    [x][x]

  6. #6
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    So wouldn't I just be better off doing something like:

    mysql_query('USE db1 SELECT * blah blah blah');
    and
    mysql_query('USE db2 SELECT * blah blah blah');
    No, however you can simply omit the mysql_select_db and do this:

    SELECT * FROM `databasename`.`tablename`


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  7. #7
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Thats much better. Thanks.
    Vouches
    [x][x]

  8. #8
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    Also, 2 more questions.

    1. I created a function. Heres the code:
    PHP Code:
    function clean($str) {
     if(!
    get_magic_quotes_gpc()){
         
    $str addslashes($str);
        }
     
    $str strip_tags(htmlspecialchars($str));
     return 
    $str;

    Thats in config.php. If I include index.php and call that function I get an error saying that I can't redeclare it. I've never gotten that error before and all the other functions I created work.

    And lets say I have these files

    -MainFolder
    --config.php
    -SecondaryFolder
    --index.php

    How should I include config.php into index.php? Should I spell out the whole url?
    Vouches
    [x][x]

  9. #9
    Join Date
    Jun 2008
    Location
    United Kingdom
    Posts
    2,015
    Tokens
    568

    Latest Awards:

    Default

    Quote Originally Posted by Fazon View Post
    And lets say I have these files

    -MainFolder
    --config.php
    -SecondaryFolder
    --index.php

    How should I include config.php into index.php? Should I spell out the whole url?
    PHP Code:
    include '../config.php'

  10. #10
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    tried that already. didnt work. maybe theres something in php.ini or apache's settings?
    Vouches
    [x][x]

Page 1 of 4 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •