MySQLi

An extension typically exposes an API to the PHP developer, to allow its facilities to be used programmatically.

MySQLi is an improved version of the older PHP MySQL driver, offering various benefits.

[3] The authors of the PHP scripting language recommend using MySQLi when dealing with MySQL server versions 4.1.3 and newer (takes advantage of new functionality).

[3] The MySQLi extension provides various benefits with respect to its predecessor, the most prominent of which (according to the PHP website[3]) are: The MySQLi extension features a dual interface - it supports both the procedural and object-oriented programming paradigms.

Users migrating from the old MySQL extension may prefer the procedural interface.

New and old native function calls The MySQL server supports the use of different transport layers for connections.

The mysqli_query() function is the most common, and combines the executing statement with a buffered fetch of its result set, if any, in one call.

With the text protocol, the MySQL server converts all data of a result sets into strings before sending.

Example: Text protocol returns strings by default The above example will output: It is possible to convert integer and float columns back to PHP numbers by setting the MYSQLI_OPT_INT_AND_FLOAT_NATIVE connection option, if using the mysqlnd library.

If set, the mysqlnd library will check the result set meta data column types and convert numeric SQL columns to PHP numbers, if the PHP data type value range allows for it.

Sending multiple statements at once reduces client-server round trips but requires special handling.

See examples in [7] The MySQL server supports transactions depending on the storage engine used.

[9] Persistent connection support was introduced in PHP 5.3 for the MySQLi extension.

Unlike the MySQL extension, MySQLi does not provide a separate function for opening persistent connections.

Any cleanup would need to be done by the new client process before it could make good use of the persistent connection, increasing the burden on the programmer.

The persistent connection of the MySQLi extension however provides built-in cleanup handling code.

The MySQLi extension does this cleanup by automatically calling the C-API function mysql_change_user().

The advantage is that the developer no longer needs to worry about adding cleanup code, as it is called automatically.