MySQL Improved Extension (
Mysqli
)
2336
being created and destroyed multiple times. This reduces the overhead of creating fresh connections
every time one is required, as unused connections are cached and ready to be reused.
Unlike the mysql extension, mysqli does not provide a separate function for opening persistent
connections. To open a persistent connection you must prepend
p:
to the hostname when connecting.
The problem with persistent connections is that they can be left in unpredictable states by clients. For
example, a table lock might be activated before a client terminates unexpectedly. A new client process
reusing this persistent connection will get the connection “as is”. 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 cleanup carried out by
mysqli
includes:
• Rollback active transactions
• Close and drop temporary tables
• Unlock tables
• Reset session variables
• Close prepared statements (always happens with PHP)
• Close handler
• Release locks acquired with
GET_LOCK
This ensures that persistent connections are in a clean state on return from the connection pool, before
the client process uses them.
The
mysqli
extension does this cleanup by automatically calling the C-API function
mysql_change_user()
.
The automatic cleanup feature has advantages and disadvantages though. The advantage is that
the programmer no longer needs to worry about adding cleanup code, as it is called automatically.
However, the disadvantage is that the code could potentially be a little slower, as the code to perform
the cleanup needs to run each time a connection is returned from the connection pool.
It is possible to switch off the automatic cleanup code, by compiling PHP with
MYSQLI_NO_CHANGE_USER_ON_PCONNECT
defined.
Note
The
mysqli
extension supports persistent connections when using either
MySQL Native Driver or MySQL Client Library.
20.7.3.6. Predefined Constants
Copyright 1997-2012 the PHP Documentation Group. [2230]
The constants below are defined by this extension, and will only be available when the extension has
either been compiled into PHP or dynamically loaded at runtime.
MYSQLI_READ_DEFAULT_GROUP
Read options from the named group from
my.cnf
or the file
specified with
MYSQLI_READ_DEFAULT_FILE
MYSQLI_READ_DEFAULT_FILE
Read options from the named option file instead of from
my.cnf
MYSQLI_OPT_CONNECT_TIMEOUT
Connect timeout in seconds
MYSQLI_OPT_LOCAL_INFILE
Enables command
LOAD LOCAL INFILE
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...