tags:

views:

102

answers:

4

I got "Warning: mysql_query(): 10 is not a valid MySQL-Link resource" referring to a line in my PHP script where I executed a query using "mysql_query($query, $link_identifier)"

+1  A: 

Then the value of $link_identifier seems to be 10 and shouldn't be:-)

Lars
It may be 10. Don't forget that resources are nothing more than a special number type. If you do `$identifier = mysql_connect()`, and then `echo $identifier;`, you'll get a number.What's more likely, is that the resource was closed prior to the execution of the query...
ircmaxell
+2  A: 

$link_identifier would have to be a value you got from mysql_connect. You don't really need to include it if you are only using one database; every mysql_ function uses the last database you mysql_connected to by default.

If you're not trying to pass a link identifier, then chances are that you're trying to use mysql_query in a way it's not intended. I'll need to see the code that calls it in order to say more.

cHao
A: 

10's a bit high for a MySQL link identifier, unless you're holding 10 open connections to MySQL in your script, or close/reconnect for each query. Are you trying to pass a previous query result instead of the DB handle? Something like this:

$dbh = mysql_connect(...);
$stmt = mysql_query('SELECT ...', $dbh);

and later on after a series of queries, maybe doing

$stmt = mysql_query('SELECT ...', $stmt); // <--using $stmt instead of $dbh

As well, though not likely, mixing mysqli and mysql handles isn't supported. They both do the same stuff and use the same libraries internally, but maintain seperate connection pools which can't be shared.

Marc B
A: 

The resource was closed prior to the execution of the query. Read comment of 'ircmaxwell' on one of the answers to this question. Thanks 'ircmaxwell'.

M LOHIT