I want to understand how many client sever calls are made for a typical mysqli query?
Step(1) $result = mysqli_query($link, $query);
Depending on the type of query, we use other mysqli function after this like
mysqli_fetch_fields, mysqli_affected_rows, mysqli_insert_id, mysqli_fetch_row
etc. then we close the result object.
Now, is all data retrieved and stored in php memory after step (1)? Or mysqli_fetch_fields, mysqli_insert_id etc makes another call to mysql server?
Reason for asking: Trying to understand how mysqli calls work. But can not find such explanation anywhere for beginners like me.
mysqli_prepare(): The above MySQLi function is used to prepare a MySQL query for execution. It returns a statement object for further operations and returns FALSE if some error occurs.
Types of MySQL Functions in PHP: Database connections. Managing Database connections. Performing Queries.
The installation process with MySQLi not only easy, but is automatic when the PHP5 MySQL package is installed in Windows or Linux. MySQLi performs (slightly) faster than its competition. With non-prepared statements, the system performs ~2.5% faster, and ~6.5% faster with prepared ones.
PHP MySQLi
API is built on MySQL C API. So it would be better if you have knowlegdes of it.
Basically, SELECT
query could generate large ResultSet and this ResultSet is transfered from Server to Client when you call PHP's mysqli_store_result()
(In C API, mysql_store_result()
).
C API mysql_fetch_row()
just returns a pointer to MYSQL_RES* (which is already stored in PHP right after mysql_store_result()
. But 'mysqli_fetch_row()` would require some memories to make PHP's array.
mysqli_insert_id()
(which is last_insert_id()
of C API) just returns insert id of MYSQL
connection data stucture which means there is no extra memory for insert id.
If you want to know how MySQLi works, I would recommand to learn MySQL C API and see PHP source codes.
mysqli_query runs the query on the server and returns false is the query failed, true is the query was successful but did not return anything (UPDATE query for example) or a mysqli_result otherwise. That mysqli_result is a class that extends Traversable interface, so yes, it's in memory. All other functions mysqli_fetch_fields, mysqli_affected_rows etc. are just methods in that class so those just read what's already in memory.
For more details, read this: php documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With