www.webdeveloper.com
Results 1 to 6 of 6

Thread: mysql_select_db supplied argument is not a valid MySQL-Link resource

  1. #1
    Join Date
    Sep 2005
    Location
    Portland Oregon
    Posts
    153

    mysql_select_db supplied argument is not a valid MySQL-Link resource

    I require_once("includefile.php"); that contains a mysql_connect() function that returns a valid Resource ID.
    Code:
    $OneSitHomeDB = mysql_connect($hostname_OneSitHomeDB, $username_OneSitHomeDB, $password_OneSitHomeDB) or die(mysql_error());
    I have a mysql_select_db() of:
    Code:
    		
    mysql_select_db($database_OneSitHomeDB, $OneSitHomeDB) or die(mysql_error() . " mysql_select_db($database_OneSitHomeDB, $OneSitHomeDB) " . __FILE__ . " : " . __LINE__);
    Note that the call and arguments are printed as part of the die() function. What is returned is:

    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in c:\Inetpub\wwwroot\OnesitHome\php-includes\_autoCache.php on line 56
    mysql_select_db(1sitHomeDB, Resource id #4) c:\Inetpub\wwwroot\OnesitHome\php-includes\_autoCache.php : 56

    As you can see from the output, the Resource ID is 'Resource id #4' which sure looks like a valid resource ID to me! I've tried restarting mySQL, restarting the webservice, etc. This same code has worked reliably (same function) in another application. But I can't figure out what's wrong or how to solve it.

    It seems to magically start working sometimes and then dies again from this error. But I can't go forward with the error.

    I have noticed that the page that uses this will sometimes have an "transferring data from pdx1" in the satus bar (which it doesn't seem like it should since the page is complete) so I'm not sure if that has anything to do with it. When I look at the connections in mysqlAdministrator it usually shows 2 but never more than 4.

    Any thoughts?

    thanks,
    tony

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    What happens when you do the resource implicitly in the call? IE just use mysql_select_db($database_OneSitHomeDB)

    I've never really seen what my resources are called, so I don't know if that's what it's supposed to look like...

  3. #3
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    "do this or die()" sooo redundant, connecting to MySQL < 4.1 is a two step process
    PHP Code:
    <?php
    $db 
    = @mysql_connect('localhost''root''');

    if(!
    $db || !@mysql_select_db('dbname'$db))
    {
        die(
    'unable to connect to mysql server: ' mysql_error());
    }
    ?>

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Quote Originally Posted by ShrineDesigns
    "do this or die()" sooo redundant, connecting to MySQL < 4.1 is a two step process
    PHP Code:
    <?php
    $db 
    = @mysql_connect('localhost''root''');

    if(!
    $db || !@mysql_select_db('dbname'$db))
    {
        die(
    'unable to connect to mysql server: ' mysql_error());
    }
    ?>
    What?

    he is doing a 2 step process. and fyi
    PHP Code:
    $link mysql_connect('server:3306''username''password') or die('Could not connect: ' mysql_error());
    $db_selected mysql_select_db('content'$link) or die ('Error while connecting to database: ' mysql_error()); 
    works perfectly fine, system's mysql 4.0.23

  5. #5
    Join Date
    Sep 2005
    Location
    Portland Oregon
    Posts
    153

    Problem seems to be with $_SESSION variables getting lost

    I'm going to post a separate question in this group to address this problem. Not sure I understand what's going on.

    tony

  6. #6
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    oh i see what the problem is...

    database, table, and column names MUST begin with a character not a numerial (sameas the rule for php variable names, if i remember correctly)
    Last edited by ShrineDesigns; 10-18-2005 at 11:57 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles