What if I call a database in single-state mode?

Source: Internet
Author: User
What if I call a database in single-state mode? If you call a database in single-state mode, the returned result set and database connection object are included in the method.
I know that the connection object is destroyed during Structure Analysis. could you tell me how to release the returned result set? I know that you can assign a value to the array in the method and then return the array to release the result set, but sometimes we need to return a result set instead of an array. Should I release the result set if I call it?
Is another method such as free () written in the class and then called outside the class? It seems that this is not easy to write. how do you deal with it.


Reply to discussion (solution)

If a result set resource is returned, it is unnecessary to encapsulate database operations.
For example

$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 some flexibility will naturally be lost.
It is obvious that the database object of a single instance only needs to cache the result set of the last query. otherwise, whether you want to read or release the database object, you will be at a loss because you do not know which result set to operate.

If a result set resource is returned, it is unnecessary to encapsulate database operations.
For example

$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 some flexibility will naturally be lost.
It is obvious that the database object of a single instance only needs to cache the result set of the last query. otherwise, whether you want to read or release the database object, you will be at a loss because you do not know which result set to operate.

Thank you for your quick reply?
The returned result set is not encapsulated. I just read that many database operation classes on the Internet use the returned result set.
Can the moderator bother me? also, how many single-state database connection projects are used?

First, let's clarify the differences between result funding sources and result set objects.
Resource in the result set, for example, a resource number returned by mysql_query ('select... ')
A result set object (object), such as a mysqli_result object returned by mysqli_query ('select... ')

You can encapsulate the database class by yourself and make db: query return an object (such as db_result)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.