PHP错误Warning:mysql_query()解决方法
更新时间:2015年10月24日 11:44:03 投稿:lijiao
这篇文章主要介绍了PHP错误Warning:mysql_query()的解决方法,希望可以真正解决大家的问题,需要的朋友可以参考下
php提示错误:Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)
代码:
<?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);
希望提供的解决方法可以真正的帮助到大家。
您可能感兴趣的文章:
- 完美解决phpdoc导出文档中@package的warning及Error的错误
- PHP Warning: Module ''modulename'' already loaded in问题解决办法
- PHP提示Warning:phpinfo() has been disabled函数禁用的解决方法
- php提示Warning:mysql_fetch_array() expects的解决方法
- php下foreach提示Warning:Invalid argument supplied for foreach()的解决方法
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- PHP错误WARNING: SESSION_START() [FUNCTION.SESSION-START]解决方法
- PHP Warning: PHP Startup: Unable to load dynamic library \ D:/php5/ext/php_mysqli.dll\
- php关闭warning问题的解决方法
最新评论