Home > Backend Development > PHP Tutorial > PHP error Warning: solution to mysql_query()_PHP tutorial

PHP error Warning: solution to mysql_query()_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 14:54:05
Original
1053 people have browsed it

php prompt error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO)

Code:

Copy to ClipboardLiehuo.Net CodesQuoted 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);

www.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....
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template