时时商务社区
标题:
PHP错误Warning:mysql_query()解决方法
[打印本页]
作者:
阿情
时间:
2018-2-14 05:42
php提示错误:
Warning: mysql_query() [function.mysql-query]: Access denied for user
[url=mailto:'ODBC'@'localhost']
'ODBC'@'localhost'
[/url]
(using password: NO)
代码:
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 Warning: PHP Startup: Unable to load dynamic library \ D:/php5/ext/php_mysqli.dll\
PHP错误WARNING: SESSION_START() [FUNCTION.SESSION-START]解决方法
PHP错误Warning: Cannot modify header information - headers already sent by解决方法
php下foreach提示Warning:Invalid argument supplied for foreach()的解决方法
php提示Warning:mysql_fetch_array() expects的解决方法
PHP提示Warning:phpinfo() has been disabled函数禁用的解决方法
PHP Warning: Module ''modulename'' already loaded in问题解决办法
完美解决phpdoc导出文档中@package的warning及Error的错误
php关闭warning问题的解决方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2