If you call the database using a single-state mode, the method has a return result set, and the database connection object
I know that the connection object is destroyed at the time of destruction, ask how to release the returned result set, I know can be assigned to the array in the method and then return the array, release the result set, but sometimes need to return the result set instead of the array, please release the result set should be called?
Do you want to write another method like free () in the class and call it outside of the class? I feel that this is not good to write, how do you deal with AH.
Reply to discussion (solution)
If the result set resource is returned, then there is no need to encapsulate the database operation.
Like what
$rs = Db::getinstance ()->query ($sql), $row = Mysql_fetch_assoc ($RS);
Don't you think it's weird?
The purpose of encapsulation is to simplify operations and naturally lose some flexibility
The singleton database object is obviously only expected to cache the result set of the last query, or you will not be confused whether you want to read or release it because you do not know which result set to manipulate.
If the result set resource is returned, then there is no need to encapsulate the database operation.
Like what
$rs = Db::getinstance ()->query ($sql), $row = Mysql_fetch_assoc ($RS);
Don't you think it's weird?
The purpose of encapsulation is to simplify operations and naturally lose some flexibility
The singleton database object is obviously only expected to cache the result set of the last query, or you will not be confused whether you want to read or release it because you do not know which result set to manipulate.
Thank you moderator Swift reply?
Returns the result set is not a matter of encapsulation, just looked at the next online many database operation classes are returned result sets Ah, dizzy AH
Moderator can be bothered to teach under, in addition to ask under the single-State connection database project use more?
Identify the difference between the result set resource and the result set object first
A resource number returned by the result set resource (resource) such as mysql_query (' Select ... ')
A Mysqli_result object returned by the result set object (object) such as Mysqli_query (' Select ... ')
You encapsulate the database class yourself, and you can let Db::query return an object (such as Db_result)