norixxx
norixxx

Reputation: 3179

mysqli_result class where does actual fetched data exits?

When mysqli_query is executed, PHP receives result set, which is a object(mysqli_result class) as far as I concern, from database(MySQL).

Does this mysqli_result class carry actual data from database in its property?

Just wondering where the results exits...

Upvotes: 1

Views: 43

Answers (2)

Dharman
Dharman

Reputation: 33315

There are two types of queries. Buffered and unbuffered. When using unbuffered queries the data is not stored in PHP memory at all.

When using buffered queries the data is fetched from the MySQL server in advance by the client library. Mysqli can use two client libraries: libmysql and mysqlnd.

When libmysqlclient is used, the data is stored by that client in memory. It is not stored within PHP memory.

When using mysqlnd (native PHP extension), the data is stored internally by mysqlnd in PHP memory.

The buffered data can be accessed using the methods of mysqli_result class or it can be copied over into an array using mysqli_fetch_all.

Mysqli doesn't actually store the data at all! If the data is buffered it is only stored by the client library in PHP memory.

Upvotes: 0

Your Common Sense
Your Common Sense

Reputation: 157889

Does this mysqli_result class carry actual data from database in its property?

No.

It carries only a link to the internal resultset that is inaccessible directly, but only through consequent calls to mysqli_result::fetch_* methods.

The result exists in the memory allocated by Mysqli module internally. It is still on the PHP side, but inaccessible directly, yet it is occupying the memory available for PHP script (this is my article about PDO, but it's applicable for mysqli as well).

The only exception is an unbuffered query. For such a query there is no resultset stored on the PHP side, the results are fetched directly from the DB.

Upvotes: 2

Related Questions