View Full Version : Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in
karen.marley367377
12-11-2009, 03:48 AM
Hi
Have set up a mysql database and working with php.
The connection works fine locally, but when I load to the remote server I get the error:
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in
My host provider seems to think this is a compatibility issue between their versions of mysql (5.0.77) and php (5.1.6) and my local mysql and php.
the offending lines include "mysql_select_db($database_dbname, $dbname);
your help is much appreciated!
Justin Nemeth
12-11-2009, 09:01 AM
Double check your login information for the database. The link being invalid means a connection was not made to the database. Your database login info is probably different on your live server.
karen.marley367377
12-11-2009, 09:35 AM
Double check your login information for the database. The link being invalid means a connection was not made to the database. Your database login info is probably different on your live server.
I have double checked with the host provider and they assure me that the connection script is correct... Any other ideas? X
Justin Nemeth
12-14-2009, 12:33 PM
The link error can really only mean it can't login to your database as far as i know. You might need to turn on PHP errors so you can see the connection error. You can add ini_set('display_errors', 'on'); to the top of your PHP page then run it again. My guess is that will show an error saying the mysql_pconnect call has failed.
$dname is the connection to your MySQL database. With your original error, it means $dbname is null which means it failed to connect to MySQL for some reason.
-justin
karen.marley367377
12-15-2009, 03:14 AM
The link error can really only mean it can't login to your database as far as i know. You might need to turn on PHP errors so you can see the connection error. You can add ini_set('display_errors', 'on'); to the top of your PHP page then run it again. My guess is that will show an error saying the mysql_pconnect call has failed.
$dname is the connection to your MySQL database. With your original error, it means $dbname is null which means it failed to connect to MySQL for some reason.
-justin
After speaking to the hosting provider it seems the error was the way that the php duplicated reference to the database.
ie.
mysql_select_db($database_DBNAME, $DBNAME);
mysql_query($query_limit_RSNAME, $DBNAME)
to get this to work I had to change the syntax to:
mysql_select_db(DBNAME);
and take out the reference to the DBNAME as follows:
mysql_query($query_limit_RSNAME).
Would this be anything to do with conflicting versions of php?.
Justin Nemeth
12-15-2009, 08:54 AM
I don't think it would be different PHP versions causing this, but I've never come across this issue either. Your changes make sense, that second arguments is actually optional anyway. If you are only using a single database connection (which in your case you seem to be), it will just default to using that connection so that is why removing the 2nd argument works ok.
-justin
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.