MySQL driver problem caused by a function

Two days ago, I used mysqli_fetch_all() in a php script to get all the result sets, but it was prompted that the method was undefined, so I had to go back and use the mysql_fetch_row() method to get records line by line, which was very slow. After querying I get:

1, mysqli_fetch_all() This function only exists in mysqlnd , which is PHP's native MySQL driver.

2, mysqlnd: Description on the PHP manual: MySQL Native Driver is a replacement for the MySQL Client Library (libmysql). MySQL Native Driver is part of the official PHP sources as of PHP 5.3.0. ( mysqlnd is a replacement for libmysql , mysqlnd is part of the official PHP resources since PHP 5.3.0 ). The libmysql driver is an older driver. It has been deprecated since PHP 5.3, and mysqlnd is recommended.

3. In the traditional way of installing PHP, we generally need to specify the following items when compiling PHP:

--with-mysql=/usr/local/mysql 
--with-pdo-mysql=/usr/local/mysql

This is actually the use of the official libmysql driver of mysql, which is an old driver. It is not recommended to use it since PHP 5.3, but mysqlnd is recommended.

4, Why use the mysqlnd driver? The official PHP manual describes:

A. The libmysql driver is written by mysql AB company (now Oracle company) and released under the mysql license agreement , so it is disabled by default in PHP. And mysqlnd is driven by the official development of php and released under the php license agreement , so it avoids the problem of license agreement and copyright.

B.  Because mysqlnd is built into the PHP source code, you do not need to pre-install mysql server when compiling and installing php, but also can provide mysql client API  (mysql_connect, pdo, mysqli ), which will reduce some workload.

C. mysqlnd is a driver specially written for php optimization. It uses the characteristics of PHP itself and has more advantages than libmysql in memory management and performance. The official test of php is: libmysql saves two copies of each record in memory, while mysqlnd only saves one copy.

D. Some new or enhanced features:
--- Enhanced persistent connections;

--- Introduce the unique function mysqli_fetch_all() ;
--- Introduce some performance statistics functions mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats(). Using the above functions, it is easy to analyze the performance bottleneck of mysql query!

--- SSL support (effective from php 5.3.3);
--- Compression protocol support;
--- Named pipe support (effective from php 5.4.0);

5. How to use mysqlnd driver? When compiling php, modify the following parameters:

--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd

Tip: If you use mysqlnd, you do not need to pre-install mysql.
Verification: If client API Version:mysqlnd is found in the mysql item output by phpinfo(), it means that the mysqlnd driver is installed successfully.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325362880&siteId=291194637