Warning: mysql_close (): 7isnotavalidMySQL-Linkresourcein. what should I do?
Source: Internet
Author: User
Warning: mysql_close (): 7isnotavalidMySQL-Linkresourcein I performed two mysql database operations in one interface. 1. the interface layout is divided into the left and right parts. when you enter the interface, the left-side content is displayed and a database operation is performed. 2. click submit on the left, and the content on the right is displayed. there is a database operation Warning: mysql_close (): 7 is not a valid MySQL-Link resource in.
I performed two mysql database operations in one interface.
1. the interface layout is divided into the left and right parts. when you enter the interface, the left-side content is displayed and a database operation is performed.
2. click submit on the left, and the content on the right is displayed. a database operation is performed.
I have a database class, which is new on the left and new on the right.
When the page is displayed, Warning: mysql_close (): 7 is not a valid MySQL-Link resource in E: \ www \ bk_hmsystem \ backstage \ db. php on line 22
This problem will not occur if I delete the database on the left.
Put mysql_close in the destructor of the database operation 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;
}
}
The red area is wrong. why?
------ Solution --------------------
It is obvious that the call is performed twice. The connection has been closed for the first time. The second error occurs. You just need to skip that step. After the script is completed, the connection is naturally disconnected.
------ Solution --------------------
Is your page composed of two framework pages?
Add some code for analysis
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service