#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Sweden
    Posts
    384
    Rep Power
    15

    Mysql_connect does not return resource


    I need to connect to two mysql servers simultaneously:

    Code:
    $server1 = mysql_connect("...", "test", "test");
    $server2 = mysql_connect("...", "test", "test");
    mysql_select_db("test", $server1);
    mysql_select_db("test", $server2);
    
    var_dump($server1);
    $server1 is bool(true), but should be a resource. mysql_select_db throws this error:
    Code:
    mysql_select_db(): supplied argument is not a valid MySQL-Link resource
    If I change to this it works however:
    I need to connect to two mysql servers simultaneously:

    Code:
    $server1 = mysql_connect("...", "test", "test");
    mysql_select_db("test");
    Any ideas what I'm doing wrong?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Texas
    Posts
    171
    Rep Power
    28
    Try

    PHP Code:
    $server1 mysql_connect("...""test""test"true);
    $server2 mysql_connect("...""test""test"true);
    mysql_select_db("test"$server1);
    mysql_select_db("test"$server2);

    var_dump($server1); 
    Originally Posted by mysql_connect
    If a second call is made to mysql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. The new_link parameter modifies this behavior and makes mysql_connect() always open a new link, even if mysql_connect() was called before with the same parameters. In SQL safe mode, this parameter is ignored.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Location
    Sweden
    Posts
    384
    Rep Power
    15
    It doesn't help, I get the same error. This all there is in my script, so there are no previous connections.

    I'm running version 5.2.6-1 btw
    Last edited by Chrille; June 29th, 2010 at 11:50 AM.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    $server1 is bool(true)
    mysql_connect will never return true. It will only return a resource link or FALSE. You must be doing something else.

    If your entire script is:
    PHP Code:
    $server1 mysql_connect("192.168.1.1""test""test");
    $server2 mysql_connect("192.168.1.2""test""test");
    mysql_select_db("test"$server1);
    mysql_select_db("test"$server2);

    var_dump($server1); 
    Then $server1 is either a resource or false. If there's more you haven't told us, that could be changing it.

    This is how you're supposed to handle multiple database connections by the way, there's no "trick" to it: it should work this way by default.

    What version of PHP are you running?

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo