I got this odd error and I can't figure out where it came from:
Warning: mysql_query(): 3 is not a valid MySQL-Link resource in (...)
What's up with the 3? I don't get it. Has anyone experienced this error themselves?
PHP uses resources as a special variable to hold links to external objects, such as files and database connections. Each resource is given an integer id. (Documentation)
If the database connection fails you'll likely get a "Specified variable is not a valid MySQL-Link resource" error, as Dan Breen mentioned, since the variable that is supposed to hold the resource is null.
Since you're getting a specific resource ID in the error message, the database connection likely closed unexpectedly for some reason. Your program still has a variable with a resource ID, but the external object no longer exists. This may be due to a
An issue with the mysql extension and
I had this error just a minute ago, it was because i was including a my database connection file which had a close connection function at the bottom. Get rid of your close connection and your be fine!
I also had this problem. In examining my code I found I had an include of a script that closed the connection, so when php tried to close it again we got the error.
To solve this, just check if the connection is open before trying to close it:
It sounds like you might be getting an error while trying to connect to the database, and the mysql handle is not actually a valid connection. If you post more code, like how you're connecting to the database, that would be more helpful. Make sure you're checking for errors, too.