Warning:mysql_close (): 7 is not a valid Mysql-link resource in, what to do with
Source: Internet
Author: User
Warning:mysql_close (): 7 is a valid Mysql-link resource in
I did two MySQL database operations in one interface.
1. The layout of the interface is divided into two blocks, and the left content is displayed when the interface is entered to perform a database operation.
2. Click on the left side of the submit, the right side of the content, there is a database operation.
I have a database class, new on the left, new once on the right.
The entry page will appear Warning:mysql_close (): 7 is not a valid Mysql-link resource in E:\www\bk_hmsystem\backstage\db.php on line 22
This problem does not occur if I delete the database operation on the left.
Mysql_close is placed in the destructor of the database operations class, as follows:
Class db
{
Private $host;
Private $user;
Private $PW;
Private $con;
Private $dbname;
function __construct ($host, $user, $PW, $dbname)
{
$this->host= $host;
$this->user= $user;
$this->pw= $PW;
$this->dbname= $dbname;
$this->connect ();
}
Function Connect ()
{
$this->con=mysql_connect ($this->host, $this->user, $this->PW);
if (! $this->con) Die (Mysql_error ());
mysql_select_db ($this->dbname, $this->con) or Die (Mysql_error ());
}
function __destruct ()
{
Mysql_close ($this->con);
}
function query ($name, $table, $cond)
{
if ($name = = "") && ($cond = = ""))
$sql = "SELECT * from $table";
Else
{
if ($name = = "")
$sql = "SELECT * from $table where $cond";
Else
{
if ($cond = = "")
$sql = "Select $name from $table";
Else
$sql = "Select $name from $table where $cond";
}
}
$result =mysql_query ($sql, $this->con);
if (! $result)
{
Die (Mysql_error ());
}
Else
return $result;
}
}
There is something wrong with the red place. Don't understand why?
------Solution--------------------
Apparently called two of times. The connection has been closed for the first time. The second time it goes wrong. You simply omit that step. After the script ends, it will naturally disconnect.
------Solution--------------------
Does your page consist of two frames pages?
Add some code to analyze it.
function __destruct ()
{
if (Is_resource ($this->con))
Mysql_close ($this->con);
else {
echo $_server[' php_self '];
Var_dump ($this->con);
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.