php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
代码:
Copy to Clipboard引用的内容:
[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");
原因:
mysqlClass第二次初使化时,先初使化mysqlClass,得到跟第一个$db相同的$this->link,然后调用__construct函数会把this->link关闭。
最后导致$db中mysql资源为空。弹出错误
解决办法:
$db=$db?$db:new mysqlClass();
或者
$this->link=mysql_connect($host,$user,$pw,true);
http://www.bkjia.com/PHPjc/364666.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/364666.htmlTechArticlephp提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) 代码: Copy to Clipboard 引用的内容: [www....