开发者

Warning: mysql_query(): 10 is not a valid MySQL-Link resource [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Warning开发者_C百科: mysql_fetch_array(): supplied argument is not a valid MySQL result

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)"


$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.


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.


I came upon this question with a desperate Google search. Something cHao and Lars said inspired me and I found my problem.

I have a database class, in addition to many other standard classes (I seem to re-write more often than re-use) that I pass the resulting database object to. I had instantiated them in the wrong order (not initializing Database first), and most calls against the Database object would succeed because of a fallback database link checker.

With a specific instance, however, this fallback was getting skipped (I have yet to determine why), and my instantiation order error was exposed.

Moral of my story: If you use classes in your application, triple check order of object creation/construction and dependencies, assuring dependent classes are loaded first.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜