PHP error Warning:mysql_query() solution, warningmysql_query_PHP tutorial

WBOY
Release: 2016-07-12 09:06:49
Original
740 people have browsed it

PHP error Warning: mysql_query() solution, warningmysql_query

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

<&#63;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"); 
Copy after login

Reason:
When mysqlClass is initialized for the second time, mysqlClass is initialized first and the same $this->link as the first $db is obtained. Then calling the __construct function will close this->link.
Finally, the mysql resource in $db is empty and an error pops up.
Solution:
$db=$db?$db:new mysqlClass();
or
$this->link=mysql_connect($host,$user,$pw,true);

I hope the solutions provided can really help everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1063894.htmlTechArticlePHP error Warning: mysql_query() solution, warningmysql_query php prompt error: Warning: mysql_query() [function.mysql -query]: Access denied for user 'ODBC'@'localhost' (using p...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template