This article mainly introduces the PHP error Warning: mysql_query () solution, hoping to solve your problems. For more information, see
This article mainly introduces the PHP error Warning: mysql_query () solution, hoping to solve your problems. For more information, see
Php error: Warning: mysql_query () [function. mysql-query]: Access denied for user 'odbc '@ 'localhost' (using password: NO)
Code:
<? Php class mysqlClass {function mysqlClass ($ host = 'localhost', $ user = 'root', $ pw = '', $ db = 'mysql ') {$ this-> link = mysql_connect ($ host, $ user, $ pw); mysql_select_db ($ db);} function query ($ SQL) {mysql_query ($ SQL );} function _ destruct () {mysql_close ($ this-> link); // multi construct will cause error} // liehuo, net} $ db = new mysqlClass (); $ db = new mysqlClass (); $ db-> query ("select * from user ");
Cause:
When mysqlClass is first made into mysqlClass for the second time, get the same $ this-> link as the first $ db, call the _ construct function to disable this-> link.
Finally, the mysql resource in $ db is empty. An error is displayed.
Solution:
$ Db = $ db? $ Db: new mysqlClass ();
Or
$ This-> link = mysql_connect ($ host, $ user, $ pw, true );
We hope that the solution can help you.