I have a CS-CART ecommerce set up on a shared server. Lately it had some problems and I’m getting mysql errors, like these ones:
PHP Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 53
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 57
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 57
PHP Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 64
PHP Warning: mysql_errno(): supplied argument is not a valid MySQL-Link resource in /home/mp/public_html/core/db/mysql.php on line 127
The weird thing is that I randomly receive the error, on random pages. It’s not something that appears on a certain page or after doing a certain thing.
To make things more complicated, this only happens sometimes. Is there any chance that this could be caused by the server/mysql process?
For example, the website loads excellent now, all features work flawlessly – I tested most of the features, pages, and I did not receive the errors. A few hours ago everything loaded slow and some of the pages returned the errors above.
Any input will be appreciated.
Thank you.
Errors like this can happen if the MySQL server isn’t reachable and PHP error handling is not implemented to anticipate this. mysql_connect() returns as MySQL resource pointer to the database server, but only if the connection actually works. If not, the resource pointer is empty and functions further down the line start to complain, which is what you’re seeing there. If this happens only intermittently, this is a typical sign of MySQL server overload.
If you’re on a shared hosting server, chances are that another tenant is sometimes exhausting all the resources, so there is little you can do. But there may be a couple of things you can do to trace the problem further. If your phpMyAdmin interface allows you access to the Status tab, you can use it to gain some insight into the MySQL server’s status.
For example, look at the number of queries it performs, and the number of simultaneous connections it allows. Sometimes, connections are denied because the max connection number is exhausted (some hosting environments allow you to change this). The server also keeps track of the failure statistics, it might give you some clues as to what’s going on.
However, if you have no access to those statistics, or can’t change any settings on the server and you are sufficiently sure that your app isn’t causing the traffic overload, you should probably open a support ticket with your hosting provider.