Questions about freeing the database result set.
Class db{
private $host;//Service Area Address
private $user;//Login account
private $pass;//Login password
private $name;//Database name
private $font;//Database Character set
private $conn;//Database connection source
private $result;//Result set
private $rowRst;//Query a single record
Private $rowArray =array ();//Query multiple records
private $rowAff;//Increase in the number of deleted record strips
Connecting to a database
Private Function Init_conn () {
if (! $this->conn=mysql_connect ($this->host, $this->user, $this->pass)) {
Exit (' Database connection error ');
}
if (!mysql_select_db ($this->name, $this->conn)) {
Exit (' Database selection error ');
}
if (!mysql_query (' SET NAMES '. $this->font)) {
Exit (' character set error ');
}
}
Execute SQL statement
Public Function _query ($sql) {
if (! $this->result=mysql_query ($sql, $this->conn)) {
Exit (' SQL execution failed ');
}
return $this->result;
}
Querying heads-up data
Public Function _fetch_array ($sql) {
$this->_query ($sql);
$this->rowrst=mysql_fetch_array ($this->RESULT,MYSQL_ASSOC);
return $this->rowrst;
}
Querying more than one piece of data
Public Function _fetch_array_list ($sql) {
$this->_query ($sql);
while (!! $rows =mysql_fetch_array ($this->result,mysql_assoc)) {
$this->rowarray[]= $rows;
}
return $this->rowarray;
}
Number of affected records of the increase and deletion
Public Function _affected_rows () {
$this->rowaff=mysql_affected_rows ();
return $this->rowaff;
}
Gets the ID number of the insert operation in the previous step
Public Function _insert_id () {
return mysql_insert_id ();
}
Releasing the result set
Public Function _free_result () {
$this->rowaff= ';
$this->rowarray= ';
$this->rowrst= ';
Mysql_free_result ($this->result);
}
Close the database
Public Function _close_conn () {
$this->_free_result ();
Mysql_close ($this->conn);
}
}
When I use _close_conn this method is, the web surface displays Mysql_free_result (): supplied argument is not a valid MySQL result resource
How to solve this problem
------Solution--------------------
In Mysql_free_result ($this->result); Before you look at what $this->result become. is not the resource you originally opened
------Solution--------------------
if (Is_resource ($this->result))
{
Mysql_free_result ($this->result);
$this->result = NULL;
}
------Solution--------------------
Your $this->result is so assigned.
$this->result=mysql_query ($sql, $this->conn)
Mysql_query only the resource is returned when the SELECT statement is executed, the other is the logical value
So Mysql_free_result ($this->result);
To write
if (Is_resource ($this->result)) mysql_free_result ($this->result);
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.