《PHP學習:PHP錯誤Warning:mysql_query()解決方法》要點:
本文介紹了PHP學習:PHP錯誤Warning:mysql_query()解決方法,希望對您有用。如果有疑問,可以聯系我們。
php提示錯誤:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
代碼:
PHP實戰
<?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");
原因:
mysqlClass第二次初使化時,先初使化mysqlClass,得到跟第一個$db相同的$this->link,然后調用__construct函數會把this->link關閉.
最后導致$db中mysql資源為空,彈出錯誤.
解決方法:
$db=$db?$db:new mysqlClass();
或者
$this->link=mysql_connect($host,$user,$pw,true); PHP實戰
希望提供的解決辦法可以真正的幫助到大家.PHP實戰
維易PHP培訓學院每天發布《PHP學習:PHP錯誤Warning:mysql_query()解決方法》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/8536.html