×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

MySQL Link-Identifier?

MySQL Link-Identifier?

MySQL Link-Identifier?

(OP)
$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

RE: MySQL Link-Identifier?

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!

RE: MySQL Link-Identifier?

(OP)
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

RE: MySQL Link-Identifier?

(OP)
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

RE: MySQL Link-Identifier?

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!

RE: MySQL Link-Identifier?

(OP)
The warning is coming from php, neither of the connect, select, or query statements dies. Really odd...:(

Celia

RE: MySQL Link-Identifier?

Have you tried explicitly testing each returned value against FALSE using the "===" operator, rather than using the "mid-statement or" construct?

______________________________________________________________________
TANSTAAFL!

RE: MySQL Link-Identifier?

(OP)
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

RE: MySQL Link-Identifier?

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close