Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Link-Identifier?

Status
Not open for further replies.

SCelia

Programmer
Feb 27, 2002
82
CA
$db = mysql_connect(hostname,username,password);

mysql_select_db(db_name,$db);

produces the error "invalid mysql link-identifer" or something to that tune. The same happens in mysql_query("query",$db);

All the params were correct, and I'm certain itts connecting because it seems to work without specifying to link-id as a var. Celia
 
If your db_name is a variable containing the name of the database to which you want to connect, you should use $db_name. ______________________________________________________________________
TANSTAAFL!
 
Well actually it's $database['dbname'] but you get the idea. My sql result resource links are not working either, however, which leads me to beleive it's not connecting properly and just not generating errors... Oh well *sigh* I'll get to the bottom of this. Celia
 
Here's the code:

mysql_connect($database['hostname'],$database['username'],$database['password']) || die (error("Could not connect to database: ".mysql_error(),1));

mysql_select_db($database['dbname']) || die (error("Could not select database: ".mysql_error(),1));

//select global/default settings/data
$result = mysql_query("SELECT * FROM fusion_globals LIMIT 1") || die (error("Could not select rows from global MySQL table: ".mysql_error(),0));

if (mysql_num_rows($result) >= 1) {

If I specify a mysql link-id I get errors that it's not a valid link-id. Now I'm getting errors that $result isn't a valid result resource even although the query is flawless (tested it through phpmyadmin). I double checked the password, host, database info, it's all correct, no errors are produced in the mysql_connect() or mysql_select_db() but still it tells me $result isn't a valid result resource... I just don't get it... Celia
 
Just as a general pointer that is probably completely unrelated to your problem, if you are using the construct:

$myvariable = somefunction(...) || die (...);

You should get in the habit of writing it:

$myvariable = somefunction(...) or die (...);

The "or" operator has a lower precedence than the "||" operator. Using "or" makes it less likely that your code will run into wierd bugs based on operator precedence.



Are you getting the warning from PHP, or is the die() function killing the script?
______________________________________________________________________
TANSTAAFL!
 
The warning is coming from php, neither of the connect, select, or query statements dies. Really odd...:( Celia
 
Have you tried explicitly testing each returned value against FALSE using the "===" operator, rather than using the "mid-statement or" construct? ______________________________________________________________________
TANSTAAFL!
 
Nope, but the mysql_connect statement returns simply the number 1. The mysql_select_db statement then generates Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource...

Not sure what to make of that... I assume 1 will never === FALSE so it should be valid right? Celia
 
You should be correct. FALSE should evaluate to 0.

Let's try another tack. Have you tried explicitly stating which database resource handle to use?

Like this:

$dbh = mysql_connect($database['hostname'],$database['username'],$database['password']) or die (error("Could not connect to database: ".mysql_error(),1));

mysql_select_db($database['dbname'], $dbh) or die (error("Could not select database: ".mysql_error(),1));

//select global/default settings/data
$result = mysql_query("SELECT * FROM fusion_globals LIMIT 1". $dbh) or die (error("Could not select rows from global MySQL table: ".mysql_error(),0));

if (mysql_num_rows($result) >= 1) { ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top