php prompt error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
Code:
Copy to ClipboardQuoted content:
[www.bkjia.com]
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");
Reason:
When mysqlClass is initialized for the second time, initialize mysqlClass first and get the same $this->link as the first $db, and then call the __construct function to close this->link.
Finally, the mysql resource in $db is empty. Popup error
Solution:
$db=$db?$db:new mysqlClass();
or
$this->link=mysql_connect($host,$user,$pw,true);
http://www.bkjia.com/PHPjc/364666.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364666.htmlTechArticlephp prompt error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC' @'localhost' (using password: NO) Code: Copy to Clipboard Quoted content: [www....