This article mainly introduces the PHP error Warning: mysql_query () solution, hoping to solve your problems. For more information, see
Php error prompt: 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.