Cari di MySQL 
    MySQL Manual
Daftar Isi
(Sebelumnya) 22.9.7. Mysqlnd query result c ...22.10. MySQL Perl API (Berikutnya)

22.9.8. Mysqlnd user handler plugin (mysqlnd_uh)

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd user handler plugin (mysqlnd_uh) allows users to set hooks for most internal calls of the MySQL native driver for PHP (mysqlnd). Mysqlnd and its plugins, including PECL/mysqlnd_uh, operate on a layer beneath the PHP MySQL extensions. A mysqlnd plugin can be considered as a proxy between the PHP MySQL extensions and the MySQL server as part of the PHP executable on the client-side. Because the plugins operates on their own layer below the PHP MySQL extensions, they can monitor and change application actions without requiring application changes. If the PHP MySQL extensions (mysqli, mysql, PDO_MYSQL) are compiled to use mysqlnd this can be used for:

  • Monitoring

    • Queries executed by any of the PHP MySQL extensions

    • Prepared statements executing by any of the PHP MySQL extensions

  • Auditing

    • Detection of database usage

    • SQL injection protection using black and white lists

  • Assorted

    • Load Balancing connections

The MySQL native driver for PHP (mysqlnd) features an internal plugin C API. C plugins, such as the mysqlnd user handler plugin, can extend the functionality of mysqlnd. PECL/mysqlnd_uh makes parts of the internal plugin C API available to the PHP user for plugin development with PHP.

Status

The mysqlnd user handler plugin is in alpha status. Take appropriate care before using it in production environments.

22.9.8.1. Security considerations

Copyright 1997-2012 the PHP Documentation Group.

PECL/mysqlnd_uh gives users access to MySQL user names, MySQL password used by any of the PHP MySQL extensions to connect to MySQL. It allows monitoring of all queries and prepared statements exposing the statement string to the user. Therefore, the extension should be installed with care. The PHP_INI_SYSTEM configuration setting mysqlnd_uh.enable can be used to prevent users from hooking mysqlnd calls.

Code obfuscators and similar technologies are not suitable to prevent monitoring of mysqlnd library activities if PECL/mysqlnd_uh is made available and the user can install a proxy, for example, using auto_prepend_file.

22.9.8.2. Documentation note

Copyright 1997-2012 the PHP Documentation Group.

Many of the mysqlnd_uh functions are briefly described because the mysqli extension is a thin abstraction layer on top of the MySQL C API that the mysqlnd library provides. Therefore, the corresponding mysqli documentation (along with the MySQL reference manual) can be consulted to receive more information about a particular function.

22.9.8.3. On the name

Copyright 1997-2012 the PHP Documentation Group.

The shortcut mysqlnd_uh stands for mysqlnd user handler, and has been the name since early development.

22.9.8.4. Quickstart and Examples

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd user handler plugin can be understood as a client-side proxy for all PHP MySQL extensions (mysqli, mysql, PDO_MYSQL), if they are compiled to use the mysqlnd library. The extensions use the mysqlnd library internally, at the C level, to communicate with the MySQL server. PECL/mysqlnd_uh allows it to hook many mysqlnd calls. Therefore, most activities of the PHP MySQL extensions can be monitored.

Because monitoring happens at the level of the library, at a layer below the application, it is possible to monitor applications without changing them.

On the C level, the mysqlnd library is structured in modules or classes. The extension hooks almost all methods of the mysqlnd internal connection class and exposes them through the user space class MysqlndUhConnection. Some few methods of the mysqlnd internal statement class are made available to the PHP user with the class MysqlndUhPreparedStatement. By subclassing the classes MysqlndUhConnection and MysqlndUhPreparedStatement users get access to mysqlnd internal function calls.

Note

The internal mysqlnd function calls are not designed to be exposed to the PHP user. Manipulating their activities may cause PHP to crash or leak memory. Often, this is not considered a bug. Please, keep in mind that you are accessing C library functions through PHP which are expected to take certain actions, which you may not be able to emulate in user space. Therefore, it is strongly recommended to always call the parent method implementation when subclassing MysqlndUhConnection or MysqlndUhPreparedStatement. To prevent the worst case, the extension performs some sanity checks. Please, see also the Mysqlnd_uh Configure Options.

22.9.8.4.1. Setup

Copyright 1997-2012 the PHP Documentation Group.

The plugin is implemented as a PHP extension. See the installation instructions to install the PECL/mysqlnd_uh extension. Then, load the extension into PHP and activate the plugin in the PHP configuration file using the PHP configuration directive named mysqlnd_uh.enable. The below example shows the default settings of the extension.

Example 22.316. Enabling the plugin (php.ini)

mysqlnd_uh.enable=1mysqlnd_uh.report_wrong_types=1
22.9.8.4.2. How it works

Copyright 1997-2012 the PHP Documentation Group.

This describes the background and inner workings of the mysqlnd_uh extension.

Two classes are provided by the extension: MysqlndUhConnection and MysqlndUhPreparedStatement. MysqlndUhConnection lets you access almost all methods of the mysqlnd internal connection class. The latter exposes some selected methods of the mysqlnd internal statement class. For example, MysqlndUhConnection::connect maps to the mysqlnd library C function mysqlnd_conn__connect.

As a mysqlnd plugin, the PECL/mysqlnd_uh extension replaces mysqlnd library C functions with its own functions. Whenever a PHP MySQL extension compiled to use mysqlnd calls a mysqlnd function, the functions installed by the plugin are executed instead of the original mysqlnd ones. For example, mysqli_connect invokes mysqlnd_conn__connect, so the connect function installed by PECL/mysqlnd_uh will be called. The functions installed by PECL/mysqlnd_uh are the methods of the built-in classes.

The built-in PHP classes and their methods do nothing but call their mysqlnd C library counterparts, to behave exactly like the original mysqlnd function they replace. The code below illustrates in pseudo-code what the extension does.

Example 22.317. Pseudo-code: what a built-in class does

class MysqlndUhConnection {  public function connect(($conn, $host, $user, $passwd, $db, $port, $socket, $mysql_flags) { MYSQLND* c_mysqlnd_connection = convert_from_php_to_c($conn); ... return call_c_function(mysqlnd_conn__connect(c_mysqlnd_connection, ...));  }}

The build-in classes behave like a transparent proxy. It is possible for you to replace the proxy with your own. This is done by subclassing MysqlndUhConnection or MysqlndUhPreparedStatement to extend the functionality of the proxy, followed by registering a new proxy object. Proxy objects are installed by mysqlnd_uh_set_connection_proxy and mysqlnd_uh_set_statement_proxy.

Example 22.318. Installing a proxy

<?phpclass proxy extends MysqlndUhConnection { public function connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");?> 

The above example will output:

proxy::connect(array (  0 => NULL,  1 => 'localhost',  2 => 'root',  3 => '',  4 => 'test',  5 => 3306,  6 => NULL,  7 => 131072,))proxy::connect returns true
22.9.8.4.3. Installing a proxy

Copyright 1997-2012 the PHP Documentation Group.

The extension provides two built-in classes: MysqlndUhConnection and MysqlndUhPreparedStatement. The classes are used for hooking mysqlnd library calls. Their methods correspond to mysqlnd internal functions. By default they act like a transparent proxy and do nothing but call their mysqlnd counterparts. By subclassing the classes you can install your own proxy to monitor mysqlnd.

See also the How it works guide to learn about the inner workings of this extension.

Connection proxies are objects of the type MysqlndUhConnection. Connection proxy objects are installed by mysqlnd_uh_set_connection_proxy. If you install the built-in class MysqlndUhConnection as a proxy, nothing happens. It behaves like a transparent proxy.

Example 22.319. Proxy registration, mysqlnd_uh.enable=1

<?phpmysqlnd_uh_set_connection_proxy(new MysqlndUhConnection());$mysqli = new mysqli("localhost", "root", "", "test");?>

The PHP_INI_SYSTEM configuration setting mysqlnd_uh.enable controls whether a proxy may be set. If disabled, the extension will throw errors of type E_WARNING

Example 22.320. Proxy installation disabled

mysqlnd_uh.enable=0 
<?phpmysqlnd_uh_set_connection_proxy(new MysqlndUhConnection());$mysqli = new mysqli("localhost", "root", "", "test");?> 

The above example will output:

PHP Warning:  MysqlndUhConnection::__construct(): (Mysqlnd User Handler) The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enabled = false.You must not use any of the base classes in %s on line %dPHP Warning:  mysqlnd_uh_set_connection_proxy(): (Mysqlnd User Handler) The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enable = false.The proxy has not been installed  in %s on line %d

To monitor mysqlnd, you have to write your own proxy object subclassing MysqlndUhConnection. Please, see the function reference for a the list of methods that can be subclassed. Alternatively, you can use reflection to inspect the built-in MysqlndUhConnection.

Create a new class proxy. Derive it from the built-in class MysqlndUhConnection. Replace the MysqlndUhConnection::connect. method. Print out the host parameter value passed to the method. Make sure that you call the parent implementation of the connect method. Failing to do so may give unexpected and undesired results, including memory leaks and crashes.

Register your proxy and open three connections using the PHP MySQL extensions mysqli, mysql, PDO_MYSQL. If the extensions have been compiled to use the mysqlnd library, the proxy::connect method will be called three times, once for each connection opened.

Example 22.321. Connection proxy

<?phpclass proxy extends MysqlndUhConnection {  public function connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags) {   printf("Connection opened to '%s'\n", $host);   /* Always call the parent implementation! */   return parent::connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags);  }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysql = mysql_connect("localhost", "root", "");$pdo = new PDO("mysql:host=localhost;dbname=test", "root", "");?> 

The above example will output:

Connection opened to 'localhost'Connection opened to 'localhost'Connection opened to 'localhost'

The use of prepared statement proxies follows the same pattern: create a proxy object of the type MysqlndUhPreparedStatement and install the proxy using mysqlnd_uh_set_statement_proxy.

Example 22.322. Prepared statement proxy

<?phpclass stmt_proxy extends MysqlndUhPreparedStatement { public function prepare($res, $query) {  printf("%s(%s)\n", __METHOD__, $query);  return parent::prepare($res, $query); }}mysqlnd_uh_set_statement_proxy(new stmt_proxy());$mysqli = new mysqli("localhost", "root", "", "test");$stmt = $mysqli->prepare("SELECT 'mysqlnd hacking made easy' AS _msg FROM DUAL");?> 

The above example will output:

stmt_proxy::prepare(SELECT 'mysqlnd hacking made easy' AS _msg FROM DUAL)
22.9.8.4.4. Basic query monitoring

Copyright 1997-2012 the PHP Documentation Group.

Basic monitoring of a query statement is easy with PECL/mysqlnd_uh. Combined with debug_print_backtrace it can become a powerful tool, for example, to find the origin of certain statement. This may be desired when searching for slow queries but also after database refactoring to find code still accessing deprecated databases or tables. The latter may be a complicated matter to do otherwise, especially if the application uses auto-generated queries.

Example 22.323. Basic Monitoring

<?phpclass conn_proxy extends MysqlndUhConnection { public function query($res, $query) {  debug_print_backtrace();  return parent::query($res, $query); }}class stmt_proxy extends MysqlndUhPreparedStatement { public function prepare($res, $query) {  debug_print_backtrace();  return parent::prepare($res, $query); }}mysqlnd_uh_set_connection_proxy(new conn_proxy());mysqlnd_uh_set_statement_proxy(new stmt_proxy());printf("Proxies installed...\n");$pdo = new PDO("mysql:host=localhost;dbname=test", "root", "");var_dump($pdo->query("SELECT 1 AS _one FROM DUAL")->fetchAll(PDO::FETCH_ASSOC));$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->prepare("SELECT 1 AS _two FROM DUAL");?> 

The above example will output:

#0  conn_proxy->query(Resource id #19, SELECT 1 AS _one FROM DUAL)#1  PDO->query(SELECT 1 AS _one FROM DUAL) called at [example.php:19]array(1) {  [0]=>  array(1) { ["_one"]=> string(1) "1"  }}#0  stmt_proxy->prepare(Resource id #753, SELECT 1 AS _two FROM DUAL)#1  mysqli->prepare(SELECT 1 AS _two FROM DUAL) called at [example.php:22]

For basic query monitoring you should install a connection and a prepared statement proxy. The connection proxy should subclass MysqlndUhConnection::query. All database queries not using native prepared statements will call this method. In the example the query function is invoked by a PDO call. By default, PDO_MySQL is using prepared statement emulation.

All native prepared statements are prepared with the prepare method of mysqlnd exported through MysqlndUhPreparedStatement::prepare. Subclass MysqlndUhPreparedStatement and overwrite prepare for native prepared statement monitoring.

22.9.8.5. Installing/Configuring

Copyright 1997-2012 the PHP Documentation Group.

22.9.8.5.1. Requirements

Copyright 1997-2012 the PHP Documentation Group.

PHP 5.3.3 or later. It is recommended to use PHP 5.4.0 or later to get access to the latest mysqlnd features.

The mysqlnd_uh user handler plugin supports all PHP applications and all available PHP MySQL extensions (mysqli, mysql, PDO_MYSQL). The PHP MySQL extension must be configured to use mysqlnd in order to be able to use the mysqlnd_uh plugin for mysqlnd.

The alpha versions makes use of some mysqli features. You must enable mysqli to compile the plugin. This requirement may be removed in the future. Note, that this requirement does not restrict you to use the plugin only with mysqli. You can use the plugin to monitor mysql, mysqli and PDO_MYSQL.

22.9.8.5.2. Installation

Copyright 1997-2012 the PHP Documentation Group.

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/mysqlnd-uh

PECL/mysqlnd_uh is currently not available on Windows. The source code of the extension makes use of C99 constructs not allowed with PHP Windows builds.

22.9.8.5.3. Runtime Configuration

Copyright 1997-2012 the PHP Documentation Group.

The behaviour of these functions is affected by settings in php.ini.

Table 22.74. Mysqlnd_uh Configure Options

NameDefaultChangeableChangelog
mysqlnd_uh.enable1PHP_INI_SYSTEM 
mysqlnd_uh.report_wrong_types1PHP_INI_ALL 

Here's a short explanation of the configuration directives.

mysqlnd_uh.enable integer

Enables or disables the plugin. If set to disabled, the extension will not allow users to plug into mysqlnd to hook mysqlnd calls.

mysqlnd_uh.report_wrong_types integer

Whether to report wrong return value types of user hooks as E_WARNING level errors. This is recommended for detecting errors.

22.9.8.5.4. Resource Types

Copyright 1997-2012 the PHP Documentation Group.

This extension has no resource types defined.

22.9.8.6. Predefined Constants

Copyright 1997-2012 the PHP Documentation Group.

The constants below are defined by this extension, andwill only be available when the extension has eitherbeen compiled into PHP or dynamically loaded at runtime.

Most of the constants refer to details of the MySQL Client Server Protocol. Please, refer to the MySQL reference manual to learn about their meaning. To avoid content duplication, only short descriptions are given.

MysqlndUhConnection::simpleCommand related

The following constants can be used to detect what command is to be send through MysqlndUhConnection::simpleCommand.

MYSQLND_UH_MYSQLND_COM_SLEEP (integer)
MySQL Client Server protocol command: COM_SLEEP.
MYSQLND_UH_MYSQLND_COM_QUIT (integer)
MySQL Client Server protocol command: COM_QUIT.
MYSQLND_UH_MYSQLND_COM_INIT_DB (integer)
MySQL Client Server protocol command: COM_INIT_DB.
MYSQLND_UH_MYSQLND_COM_QUERY (integer)
MySQL Client Server protocol command: COM_QUERY.
MYSQLND_UH_MYSQLND_COM_FIELD_LIST (integer)
MySQL Client Server protocol command: COM_FIELD_LIST.
MYSQLND_UH_MYSQLND_COM_CREATE_DB (integer)
MySQL Client Server protocol command: COM_CREATE_DB.
MYSQLND_UH_MYSQLND_COM_DROP_DB (integer)
MySQL Client Server protocol command: COM_DROP_DB.
MYSQLND_UH_MYSQLND_COM_REFRESH (integer)
MySQL Client Server protocol command: COM_REFRESH.
MYSQLND_UH_MYSQLND_COM_SHUTDOWN (integer)
MySQL Client Server protocol command: COM_SHUTDOWN.
MYSQLND_UH_MYSQLND_COM_STATISTICS (integer)
MySQL Client Server protocol command: COM_STATISTICS.
MYSQLND_UH_MYSQLND_COM_PROCESS_INFO (integer)
MySQL Client Server protocol command: COM_PROCESS_INFO.
MYSQLND_UH_MYSQLND_COM_CONNECT (integer)
MySQL Client Server protocol command: COM_CONNECT.
MYSQLND_UH_MYSQLND_COM_PROCESS_KILL (integer)
MySQL Client Server protocol command: COM_PROCESS_KILL.
MYSQLND_UH_MYSQLND_COM_DEBUG (integer)
MySQL Client Server protocol command: COM_DEBUG.
MYSQLND_UH_MYSQLND_COM_PING (integer)
MySQL Client Server protocol command: COM_PING.
MYSQLND_UH_MYSQLND_COM_TIME (integer)
MySQL Client Server protocol command: COM_TIME.
MYSQLND_UH_MYSQLND_COM_DELAYED_INSERT (integer)
MySQL Client Server protocol command: COM_DELAYED_INSERT.
MYSQLND_UH_MYSQLND_COM_CHANGE_USER (integer)
MySQL Client Server protocol command: COM_CHANGE_USER.
MYSQLND_UH_MYSQLND_COM_BINLOG_DUMP (integer)
MySQL Client Server protocol command: COM_BINLOG_DUMP.
MYSQLND_UH_MYSQLND_COM_TABLE_DUMP (integer)
MySQL Client Server protocol command: COM_TABLE_DUMP.
MYSQLND_UH_MYSQLND_COM_CONNECT_OUT (integer)
MySQL Client Server protocol command: COM_CONNECT_OUT.
MYSQLND_UH_MYSQLND_COM_REGISTER_SLAVED (integer)
MySQL Client Server protocol command: COM_REGISTER_SLAVED.
MYSQLND_UH_MYSQLND_COM_STMT_PREPARE (integer)
MySQL Client Server protocol command: COM_STMT_PREPARE.
MYSQLND_UH_MYSQLND_COM_STMT_EXECUTE (integer)
MySQL Client Server protocol command: COM_STMT_EXECUTE.
MYSQLND_UH_MYSQLND_COM_STMT_SEND_LONG_DATA (integer)
MySQL Client Server protocol command: COM_STMT_SEND_LONG_DATA.
MYSQLND_UH_MYSQLND_COM_STMT_CLOSE (integer)
MySQL Client Server protocol command: COM_STMT_CLOSE.
MYSQLND_UH_MYSQLND_COM_STMT_RESET (integer)
MySQL Client Server protocol command: COM_STMT_RESET.
MYSQLND_UH_MYSQLND_COM_SET_OPTION (integer)
MySQL Client Server protocol command: COM_SET_OPTION.
MYSQLND_UH_MYSQLND_COM_STMT_FETCH (integer)
MySQL Client Server protocol command: COM_STMT_FETCH.
MYSQLND_UH_MYSQLND_COM_DAEMON (integer)
MySQL Client Server protocol command: COM_DAEMON.
MYSQLND_UH_MYSQLND_COM_END (integer)
MySQL Client Server protocol command: COM_END.

The following constants can be used to analyze the ok_packet argument of MysqlndUhConnection::simpleCommand.

MYSQLND_UH_MYSQLND_PROT_GREET_PACKET (integer)
MySQL Client Server protocol packet: greeting.
MYSQLND_UH_MYSQLND_PROT_AUTH_PACKET (integer)
MySQL Client Server protocol packet: authentication.
MYSQLND_UH_MYSQLND_PROT_OK_PACKET (integer)
MySQL Client Server protocol packet: OK.
MYSQLND_UH_MYSQLND_PROT_EOF_PACKET (integer)
MySQL Client Server protocol packet: EOF.
MYSQLND_UH_MYSQLND_PROT_CMD_PACKET (integer)
MySQL Client Server protocol packet: command.
MYSQLND_UH_MYSQLND_PROT_RSET_HEADER_PACKET (integer)
MySQL Client Server protocol packet: result set header.
MYSQLND_UH_MYSQLND_PROT_RSET_FLD_PACKET (integer)
MySQL Client Server protocol packet: resultset field.
MYSQLND_UH_MYSQLND_PROT_ROW_PACKET (integer)
MySQL Client Server protocol packet: row.
MYSQLND_UH_MYSQLND_PROT_STATS_PACKET (integer)
MySQL Client Server protocol packet: stats.
MYSQLND_UH_MYSQLND_PREPARE_RESP_PACKET (integer)
MySQL Client Server protocol packet: prepare response.
MYSQLND_UH_MYSQLND_CHG_USER_RESP_PACKET (integer)
MySQL Client Server protocol packet: change user response.
MYSQLND_UH_MYSQLND_PROT_LAST (integer)
No practical meaning. Last entry marker of internal C data structure list.

MysqlndUhConnection::close related

The following constants can be used to detect why a connection has been closed through MysqlndUhConnection::close().

MYSQLND_UH_MYSQLND_CLOSE_EXPLICIT (integer)
User has called mysqlnd to close the connection.
MYSQLND_UH_MYSQLND_CLOSE_IMPLICIT (integer)
Implicitly closed, for example, during garbage connection.
MYSQLND_UH_MYSQLND_CLOSE_DISCONNECTED (integer)
Connection error.
MYSQLND_UH_MYSQLND_CLOSE_LAST (integer)
No practical meaning. Last entry marker of internal C data structure list.

MysqlndUhConnection::setServerOption() related

The following constants can be used to detect which option is set through MysqlndUhConnection::setServerOption().

MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_ON (integer)
Option: enables multi statement support.
MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_OFF (integer)
Option: disables multi statement support.

MysqlndUhConnection::setClientOption related

The following constants can be used to detect which option is set through MysqlndUhConnection::setClientOption.

MYSQLND_UH_MYSQLND_OPTION_OPT_CONNECT_TIMEOUT (integer)
Option: connection timeout.
MYSQLND_UH_MYSQLND_OPTION_OPT_COMPRESS (integer)
Option: whether the MySQL compressed protocol is to be used.
MYSQLND_UH_MYSQLND_OPTION_OPT_NAMED_PIPE (integer)
Option: named pipe to use for connection (Windows).
MYSQLND_UH_MYSQLND_OPTION_INIT_COMMAND (integer)
Option: init command to execute upon connect.
MYSQLND_UH_MYSQLND_READ_DEFAULT_FILE (integer)
Option: MySQL server default file to read upon connect.
MYSQLND_UH_MYSQLND_READ_DEFAULT_GROUP (integer)
Option: MySQL server default file group to read upon connect.
MYSQLND_UH_MYSQLND_SET_CHARSET_DIR (integer)
Option: charset description files directory.
MYSQLND_UH_MYSQLND_SET_CHARSET_NAME (integer)
Option: charset name.
MYSQLND_UH_MYSQLND_OPT_LOCAL_INFILE (integer)
Option: Whether to allow LOAD DATA LOCAL INFILE use.
MYSQLND_UH_MYSQLND_OPT_PROTOCOL (integer)
Option: supported protocol version.
MYSQLND_UH_MYSQLND_SHARED_MEMORY_BASE_NAME (integer)
Option: shared memory base name for shared memory connections.
MYSQLND_UH_MYSQLND_OPT_READ_TIMEOUT (integer)
Option: connection read timeout.
MYSQLND_UH_MYSQLND_OPT_WRITE_TIMEOUT (integer)
Option: connection write timeout.
MYSQLND_UH_MYSQLND_OPT_USE_RESULT (integer)
Option: unbuffered result sets.
MYSQLND_UH_MYSQLND_OPT_USE_REMOTE_CONNECTION (integer)
Embedded server related.
MYSQLND_UH_MYSQLND_OPT_USE_EMBEDDED_CONNECTION (integer)
Embedded server related.
MYSQLND_UH_MYSQLND_OPT_GUESS_CONNECTION (integer)
TODO
MYSQLND_UH_MYSQLND_SET_CLIENT_IP (integer)
TODO
MYSQLND_UH_MYSQLND_SECURE_AUTH (integer)
TODO
MYSQLND_UH_MYSQLND_REPORT_DATA_TRUNCATION (integer)
Option: Whether to report data truncation.
MYSQLND_UH_MYSQLND_OPT_RECONNECT (integer)
Option: Whether to reconnect automatically.
MYSQLND_UH_MYSQLND_OPT_SSL_VERIFY_SERVER_CERT (integer)
Option: TODO
MYSQLND_UH_MYSQLND_OPT_NET_CMD_BUFFER_SIZE (integer)
Option: mysqlnd network buffer size for commands.
MYSQLND_UH_MYSQLND_OPT_NET_READ_BUFFER_SIZE (integer)
Option: mysqlnd network buffer size for reading from the server.
MYSQLND_UH_MYSQLND_OPT_SSL_KEY (integer)
Option: SSL key.
MYSQLND_UH_MYSQLND_OPT_SSL_CERT (integer)
Option: SSL certificate.
MYSQLND_UH_MYSQLND_OPT_SSL_CA (integer)
Option: SSL CA.
MYSQLND_UH_MYSQLND_OPT_SSL_CAPATH (integer)
Option: Path to SSL CA.
MYSQLND_UH_MYSQLND_OPT_SSL_CIPHER (integer)
Option: SSL cipher.
MYSQLND_UH_MYSQLND_OPT_SSL_PASSPHRASE (integer)
Option: SSL passphrase.
MYSQLND_UH_SERVER_OPTION_PLUGIN_DIR (integer)
Option: server plugin directory.
MYSQLND_UH_SERVER_OPTION_DEFAULT_AUTH (integer)
Option: default authentication method.
MYSQLND_UH_SERVER_OPTION_SET_CLIENT_IP (integer)
TODO
MYSQLND_UH_MYSQLND_OPT_MAX_ALLOWED_PACKET (integer)
Option: maximum allowed packet size. Available as of PHP 5.4.0.
MYSQLND_UH_MYSQLND_OPT_AUTH_PROTOCOL (integer)
Option: TODO. Available as of PHP 5.4.0.
MYSQLND_UH_MYSQLND_OPT_INT_AND_FLOAT_NATIVE (integer)
Option: make mysqlnd return integer and float columns as long even when using the MySQL Client Server text protocol. Only available with a custom build of mysqlnd.

Other

The plugins version number can be obtained using MYSQLND_UH_VERSION or MYSQLND_UH_VERSION_ID . MYSQLND_UH_VERSION is the string representation of the numerical version number MYSQLND_UH_VERSION_ID , which is an integer such as 10000. Developers can calculate the version number as follows.

Version (part)Example
Major*100001*10000 = 10000
Minor*1000*100 = 0
Patch0 = 0
MYSQLND_UH_VERSION_ID10000

MYSQLND_UH_VERSION (string)
Plugin version string, for example, "1.0.0-alpha".
MYSQLND_UH_VERSION_ID (integer)
Plugin version number, for example, 10000.

22.9.8.7. The MysqlndUhConnection class (MysqlndUhConnection)

Copyright 1997-2012 the PHP Documentation Group.

 MysqlndUhConnection {
MysqlndUhConnectionMethods public bool MysqlndUhConnection::changeUser(mysqlnd_connection connection,
string user,
string password,
string database,
bool silent,
int passwd_len);
public string MysqlndUhConnection::charsetName(mysqlnd_connection connection);
public bool MysqlndUhConnection::close(mysqlnd_connection connection,
int close_type);
public bool MysqlndUhConnection::connect(mysqlnd_connection connection,
string host,
string use",
string password,
string database,
int port,
string socket,
int mysql_flags);
public MysqlndUhConnection::__construct();
public bool MysqlndUhConnection::endPSession(mysqlnd_connection connection);
public string MysqlndUhConnection::escapeString(mysqlnd_connection connection,
string escape_string);
public int MysqlndUhConnection::getAffectedRows(mysqlnd_connection connection);
public int MysqlndUhConnection::getErrorNumber(mysqlnd_connection connection);
public string MysqlndUhConnection::getErrorString(mysqlnd_connection connection);
public int MysqlndUhConnection::getFieldCount(mysqlnd_connection connection);
public string MysqlndUhConnection::getHostInformation(mysqlnd_connection connection);
public int MysqlndUhConnection::getLastInsertId(mysqlnd_connection connection);
public void MysqlndUhConnection::getLastMessage(mysqlnd_connection connection);
public string MysqlndUhConnection::getProtocolInformation(mysqlnd_connection connection);
public string MysqlndUhConnection::getServerInformation(mysqlnd_connection connection);
public string MysqlndUhConnection::getServerStatistics(mysqlnd_connection connection);
public int MysqlndUhConnection::getServerVersion(mysqlnd_connection connection);
public string MysqlndUhConnection::getSqlstate(mysqlnd_connection connection);
public array MysqlndUhConnection::getStatistics(mysqlnd_connection connection);
public int MysqlndUhConnection::getThreadId(mysqlnd_connection connection);
public int MysqlndUhConnection::getWarningCount(mysqlnd_connection connection);
public bool MysqlndUhConnection::init(mysqlnd_connection connection);
public bool MysqlndUhConnection::killConnection(mysqlnd_connection connection,
int pid);
public array MysqlndUhConnection::listFields(mysqlnd_connection connection,
string table,
string achtung_wild);
public void MysqlndUhConnection::listMethod(mysqlnd_connection connection,
string query,
string achtung_wild,
string par1);
public bool MysqlndUhConnection::moreResults(mysqlnd_connection connection);
public bool MysqlndUhConnection::nextResult(mysqlnd_connection connection);
public bool MysqlndUhConnection::ping(mysqlnd_connection connection);
public bool MysqlndUhConnection::query(mysqlnd_connection connection,
string query);
public bool MysqlndUhConnection::queryReadResultsetHeader(mysqlnd_connection connection,
mysqlnd_statement mysqlnd_stmt);
public bool MysqlndUhConnection::reapQuery(mysqlnd_connection connection);
public bool MysqlndUhConnection::refreshServer(mysqlnd_connection connection,
int options);
public bool MysqlndUhConnection::restartPSession(mysqlnd_connection connection);
public bool MysqlndUhConnection::selectDb(mysqlnd_connection connection,
string database);
public bool MysqlndUhConnection::sendClose(mysqlnd_connection connection);
public bool MysqlndUhConnection::sendQuery(mysqlnd_connection connection,
string query);
public bool MysqlndUhConnection::serverDumpDebugInformation(mysqlnd_connection connection);
public bool MysqlndUhConnection::setAutocommit(mysqlnd_connection connection,
int mode);
public bool MysqlndUhConnection::setCharset(mysqlnd_connection connection,
string charset);
public bool MysqlndUhConnection::setClientOption(mysqlnd_connection connection,
int option,
int value);
public void MysqlndUhConnection::setServerOption(mysqlnd_connection connection,
int option);
public void MysqlndUhConnection::shutdownServer(string MYSQLND_UH_RES_MYSQLND_NAME,
string "level");
public bool MysqlndUhConnection::simpleCommand(mysqlnd_connection connection,
int command,
string arg,
int ok_packet,
bool silent,
bool ignore_upsert_status);
public bool MysqlndUhConnection::simpleCommandHandleResponse(mysqlnd_connection connection,
int ok_packet,
bool silent,
int command,
bool ignore_upsert_status);
public bool MysqlndUhConnection::sslSet(mysqlnd_connection connection,
string key,
string cert,
string ca,
string capath,
string cipher);
public resource MysqlndUhConnection::stmtInit(mysqlnd_connection connection);
public resource MysqlndUhConnection::storeResult(mysqlnd_connection connection);
public bool MysqlndUhConnection::txCommit(mysqlnd_connection connection);
public bool MysqlndUhConnection::txRollback(mysqlnd_connection connection);
public resource MysqlndUhConnection::useResult(mysqlnd_connection connection);
}
22.9.8.7.1. MysqlndUhConnection::changeUser

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::changeUser

    Changes the user of the specified mysqlnd database connection

Description

public bool MysqlndUhConnection::changeUser(mysqlnd_connection connection,
string user,
string password,
string database,
bool silent,
int passwd_len);

Changes the user of the specified mysqlnd database connection

Parameters

connection

Mysqlnd connection handle. Do not modify!

user

The MySQL user name.

password

The MySQL password.

database

The MySQL database to change to.

silent

Controls if mysqlnd is allowed to emit errors or not.

passwd_len

Length of the MySQL password.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.324. MysqlndUhConnection::changeUserexample

<?phpclass proxy extends MysqlndUhConnection { /* Hook mysqlnd's connection::change_user call */ public function changeUser($res, $user, $passwd, $db, $silent, $passwd_len) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::changeUser($res, $user, $passwd, $db, $silent, $passwd_len);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}/* Install proxy/hooks to be used with all future mysqlnd connection */mysqlnd_uh_set_connection_proxy(new proxy());/* Create mysqli connection which is using the mysqlnd library */$mysqli = new mysqli("localhost", "root", "", "test");/* Example of a user API call which triggers the hooked mysqlnd call */var_dump($mysqli->change_user("root", "bar", "test"));?> 

The above example will output:

proxy::changeUser(array (  0 => NULL,  1 => 'root',  2 => 'bar',  3 => 'test',  4 => false,  5 => 3,))proxy::changeUser returns falsebool(false)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_change_user
22.9.8.7.2. MysqlndUhConnection::charsetName

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::charsetName

    Returns the default character set for the database connection

Description

public string MysqlndUhConnection::charsetName(mysqlnd_connection connection);

Returns the default character set for the database connection.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The default character set.

Examples

Example 22.325. MysqlndUhConnection::charsetNameexample

<?phpclass proxy extends MysqlndUhConnection {  public function charsetName($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::charsetName($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump(mysqli_character_set_name($mysqli));?> 

The above example will output:

proxy::charsetName(array (  0 => NULL,))proxy::charsetName returns 'latin1'string(6) "latin1"

See Also

mysqlnd_uh_set_connection_proxy
mysqli_character_set_name
22.9.8.7.3. MysqlndUhConnection::close

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::close

    Closes a previously opened database connection

Description

public bool MysqlndUhConnection::close(mysqlnd_connection connection,
int close_type);

Closes a previously opened database connection.

Note

Failing to call the parent implementation may cause memory leaks or crash PHP. This is not considered a bug. Please, keep in mind that the mysqlnd library functions have never been designed to be exposed to the user space.

Parameters

connection

The connection to be closed. Do not modify!

close_type

Why the connection is to be closed. The value of close_type is one of MYSQLND_UH_MYSQLND_CLOSE_EXPLICIT , MYSQLND_UH_MYSQLND_CLOSE_IMPLICIT , MYSQLND_UH_MYSQLND_CLOSE_DISCONNECTED or MYSQLND_UH_MYSQLND_CLOSE_LAST . The latter should never be seen, unless the default behaviour of the mysqlnd library has been changed by a plugin.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.326. MysqlndUhConnection::closeexample

<?phpfunction close_type_to_string($close_type) { $mapping = array(  MYSQLND_UH_MYSQLND_CLOSE_DISCONNECTED => "MYSQLND_UH_MYSQLND_CLOSE_DISCONNECTED",  MYSQLND_UH_MYSQLND_CLOSE_EXPLICIT => "MYSQLND_UH_MYSQLND_CLOSE_EXPLICIT",  MYSQLND_UH_MYSQLND_CLOSE_IMPLICIT => "MYSQLND_UH_MYSQLND_CLOSE_IMPLICIT",  MYSQLND_UH_MYSQLND_CLOSE_LAST => "MYSQLND_UH_MYSQLND_CLOSE_IMPLICIT" ); return (isset($mapping[$close_type])) ? $mapping[$close_type] : 'unknown';}class proxy extends MysqlndUhConnection {  public function close($res, $close_type) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   printf("close_type = %s\n", close_type_to_string($close_type));   /* WARNING: you must call the parent */   $ret = parent::close($res, $close_type);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->close();?> 

The above example will output:

proxy::close(array (  0 => NULL,  1 => 0,))close_type = MYSQLND_UH_MYSQLND_CLOSE_EXPLICITproxy::close returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_close
mysql_close
22.9.8.7.4. MysqlndUhConnection::connect

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::connect

    Open a new connection to the MySQL server

Description

public bool MysqlndUhConnection::connect(mysqlnd_connection connection,
string host,
string use",
string password,
string database,
int port,
string socket,
int mysql_flags);

Open a new connection to the MySQL server.

Parameters

connection

Mysqlnd connection handle. Do not modify!

host

Can be either a host name or an IP address. Passing the NULL value or the string "localhost" to this parameter, the local host is assumed. When possible, pipes will be used instead of the TCP/IP protocol.

user

The MySQL user name.

password

If not provided or NULL , the MySQL server will attempt to authenticate the user against those user records which have no password only. This allows one username to be used with different permissions (depending on if a password as provided or not).

database

If provided will specify the default database to be used when performing queries.

port

Specifies the port number to attempt to connect to the MySQL server.

socket

Specifies the socket or named pipe that should be used. If NULL , mysqlnd will default to /tmp/mysql.sock.

mysql_flags

Connection options.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.327. MysqlndUhConnection::connectexample

<?phpclass proxy extends MysqlndUhConnection { public function connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::connect($res, $host, $user, $passwd, $db, $port, $socket, $mysql_flags);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");?> 

The above example will output:

proxy::connect(array (  0 => NULL,  1 => 'localhost',  2 => 'root',  3 => '',  4 => 'test',  5 => 3306,  6 => NULL,  7 => 131072,))proxy::connect returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_connect
mysql_connect
22.9.8.7.5. MysqlndUhConnection::__construct

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::__construct

    The __construct purpose

Description

public MysqlndUhConnection::__construct();

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

22.9.8.7.6. MysqlndUhConnection::endPSession

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::endPSession

    End a persistent connection

Description

public bool MysqlndUhConnection::endPSession(mysqlnd_connection connection);

End a persistent connection

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.328. MysqlndUhConnection::endPSessionexample

<?phpclass proxy extends MysqlndUhConnection { public function endPSession($conn) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::endPSession($conn);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("p:localhost", "root", "", "test");$mysqli->close();?> 

The above example will output:

proxy::endPSession(array (  0 => NULL,))proxy::endPSession returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.7. MysqlndUhConnection::escapeString

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::escapeString

    Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection

Description

public string MysqlndUhConnection::escapeString(mysqlnd_connection connection,
string escape_string);

Escapes special characters in a string for use in an SQL statement, taking into account the current charset of the connection.

Parameters

MYSQLND_UH_RES_MYSQLND_NAME

Mysqlnd connection handle. Do not modify!

escape_string

The string to be escaped.

Return Values

The escaped string.

Examples

Example 22.329. MysqlndUhConnection::escapeStringexample

<?phpclass proxy extends MysqlndUhConnection { public function escapeString($res, $string) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::escapeString($res, $string);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->set_charset("latin1");$mysqli->real_escape_string("test0'test");?> 

The above example will output:

proxy::escapeString(array (  0 => NULL,  1 => 'test0\'test',))proxy::escapeString returns 'test0\\\'test'

See Also

mysqlnd_uh_set_connection_proxy
mysqli_real_escape_string
mysql_real_escape_string
22.9.8.7.8. MysqlndUhConnection::getAffectedRows

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getAffectedRows

    Gets the number of affected rows in a previous MySQL operation

Description

public int MysqlndUhConnection::getAffectedRows(mysqlnd_connection connection);

Gets the number of affected rows in a previous MySQL operation.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Number of affected rows.

Examples

Example 22.330. MysqlndUhConnection::getAffectedRowsexample

<?phpclass proxy extends MysqlndUhConnection { public function getAffectedRows($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getAffectedRows($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("DROP TABLE IF EXISTS test");$mysqli->query("CREATE TABLE test(id INT)");$mysqli->query("INSERT INTO test(id) VALUES (1)");var_dump($mysqli->affected_rows);?> 

The above example will output:

proxy::getAffectedRows(array (  0 => NULL,))proxy::getAffectedRows returns 1int(1)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_affected_rows
mysql_affected_rows
22.9.8.7.9. MysqlndUhConnection::getErrorNumber

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getErrorNumber

    Returns the error code for the most recent function call

Description

public int MysqlndUhConnection::getErrorNumber(mysqlnd_connection connection);

Returns the error code for the most recent function call.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Error code for the most recent function call.

Examples

MysqlndUhConnection::getErrorNumber is not only executed after the invocation of a user space API call which maps directly to it but also called internally.

Example 22.331. MysqlndUhConnection::getErrorNumberexample

<?phpclass proxy extends MysqlndUhConnection { public function getErrorNumber($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getErrorNumber($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());printf("connect...\n");$mysqli = new mysqli("localhost", "root", "", "test");printf("query...\n");$mysqli->query("PLEASE_LET_THIS_BE_INVALID_SQL");printf("errno...\n");var_dump($mysqli->errno);printf("close...\n");$mysqli->close();?> 

The above example will output:

connect...proxy::getErrorNumber(array (  0 => NULL,))proxy::getErrorNumber returns 0query...errno...proxy::getErrorNumber(array (  0 => NULL,))proxy::getErrorNumber returns 1064int(1064)close...

See Also

mysqlnd_uh_set_connection_proxy
MysqlndUhConnection::getErrorString
mysqli_errno
mysql_errno
22.9.8.7.10. MysqlndUhConnection::getErrorString

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getErrorString

    Returns a string description of the last error

Description

public string MysqlndUhConnection::getErrorString(mysqlnd_connection connection);

Returns a string description of the last error.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Error string for the most recent function call.

Examples

MysqlndUhConnection::getErrorString is not only executed after the invocation of a user space API call which maps directly to it but also called internally.

Example 22.332. MysqlndUhConnection::getErrorStringexample

<?phpclass proxy extends MysqlndUhConnection { public function getErrorString($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getErrorString($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());printf("connect...\n");$mysqli = new mysqli("localhost", "root", "", "test");printf("query...\n");$mysqli->query("WILL_I_EVER_LEARN_SQL?");printf("errno...\n");var_dump($mysqli->error);printf("close...\n");$mysqli->close();?> 

The above example will output:

connect...proxy::getErrorString(array (  0 => NULL,))proxy::getErrorString returns ''query...errno...proxy::getErrorString(array (  0 => NULL,))proxy::getErrorString returns 'You have an error in your SQL syntax; checkthe manual that corresponds to your MySQL server version for the right syntaxto use near \'WILL_I_EVER_LEARN_SQL?\' at line 1'string(168) "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WILL_I_EVER_LEARN_SQL?' at line 1"close...

See Also

mysqlnd_uh_set_connection_proxy
MysqlndUhConnection::getErrorNumber
mysqli_error
mysql_error
22.9.8.7.11. MysqlndUhConnection::getFieldCount

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getFieldCount

    Returns the number of columns for the most recent query

Description

public int MysqlndUhConnection::getFieldCount(mysqlnd_connection connection);

Returns the number of columns for the most recent query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Number of columns.

Examples

MysqlndUhConnection::getFieldCount is not only executed after the invocation of a user space API call which maps directly to it but also called internally.

Example 22.333. MysqlndUhConnection::getFieldCountexample

<?phpclass proxy extends MysqlndUhConnection { public function getFieldCount($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getFieldCount($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("WILL_I_EVER_LEARN_SQL?");var_dump($mysqli->field_count);$mysqli->query("SELECT 1, 2, 3 FROM DUAL");var_dump($mysqli->field_count);?> 

The above example will output:

proxy::getFieldCount(array (  0 => NULL,))proxy::getFieldCount returns 0int(0)proxy::getFieldCount(array (  0 => NULL,))proxy::getFieldCount returns 3proxy::getFieldCount(array (  0 => NULL,))proxy::getFieldCount returns 3int(3)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_field_count
22.9.8.7.12. MysqlndUhConnection::getHostInformation

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getHostInformation

    Returns a string representing the type of connection used

Description

public string MysqlndUhConnection::getHostInformation(mysqlnd_connection connection);

Returns a string representing the type of connection used.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Connection description.

Examples

Example 22.334. MysqlndUhConnection::getHostInformationexample

<?phpclass proxy extends MysqlndUhConnection { public function getHostInformation($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getHostInformation($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->host_info);?> 

The above example will output:

proxy::getHostInformation(array (  0 => NULL,))proxy::getHostInformation returns 'Localhost via UNIX socket'string(25) "Localhost via UNIX socket"

See Also

mysqlnd_uh_set_connection_proxy
mysqli_get_host_info
mysql_get_host_info
22.9.8.7.13. MysqlndUhConnection::getLastInsertId

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getLastInsertId

    Returns the auto generated id used in the last query.

Description

public int MysqlndUhConnection::getLastInsertId(mysqlnd_connection connection);

Returns the auto generated id used in the last query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Last insert id.

Examples

Example 22.335. MysqlndUhConnection::getLastInsertIdexample

<?phpclass proxy extends MysqlndUhConnection { public function getLastInsertId($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getLastInsertId($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("DROP TABLE IF EXISTS test");$mysqli->query("CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY, col VARCHAR(255))");$mysqli->query("INSERT INTO test(col) VALUES ('a')");var_dump($mysqli->insert_id);?> 

The above example will output:

proxy::getLastInsertId(array (  0 => NULL,))proxy::getLastInsertId returns 1int(1)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_insert_id
mysql_insert_id
22.9.8.7.14. MysqlndUhConnection::getLastMessage

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getLastMessage

    Retrieves information about the most recently executed query

Description

public void MysqlndUhConnection::getLastMessage(mysqlnd_connection connection);

Retrieves information about the most recently executed query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Last message. Trying to return a string longer than 511 bytes will cause an error of the type E_WARNING and result in the string being truncated.

Examples

Example 22.336. MysqlndUhConnection::getLastMessageexample

<?phpclass proxy extends MysqlndUhConnection { public function getLastMessage($res) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::getLastMessage($res);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->info);$mysqli->query("DROP TABLE IF EXISTS test");var_dump($mysqli->info);?> 

The above example will output:

proxy::getLastMessage(array (  0 => NULL,))proxy::getLastMessage returns ''string(0) ""proxy::getLastMessage(array (  0 => NULL,))proxy::getLastMessage returns ''string(0) ""

See Also

mysqlnd_uh_set_connection_proxy
mysqli_info
mysql_info
22.9.8.7.15. MysqlndUhConnection::getProtocolInformation

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getProtocolInformation

    Returns the version of the MySQL protocol used

Description

public string MysqlndUhConnection::getProtocolInformation(mysqlnd_connection connection);

Returns the version of the MySQL protocol used.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The protocol version.

Examples

Example 22.337. MysqlndUhConnection::getProtocolInformationexample

<?phpclass proxy extends MysqlndUhConnection { public function getProtocolInformation($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getProtocolInformation($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->protocol_version);?> 

The above example will output:

proxy::getProtocolInformation(array (  0 => NULL,))proxy::getProtocolInformation returns 10int(10)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_get_proto_info
mysql_get_proto_info
22.9.8.7.16. MysqlndUhConnection::getServerInformation

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getServerInformation

    Returns the version of the MySQL server

Description

public string MysqlndUhConnection::getServerInformation(mysqlnd_connection connection);

Returns the version of the MySQL server.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The server version.

Examples

Example 22.338. MysqlndUhConnection::getServerInformationexample

<?phpclass proxy extends MysqlndUhConnection { public function getServerInformation($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getServerInformation($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->server_info);?> 

The above example will output:

proxy::getServerInformation(array (  0 => NULL,))proxy::getServerInformation returns '5.1.45-debug-log'string(16) "5.1.45-debug-log"

See Also

mysqlnd_uh_set_connection_proxy
mysqli_get_server_info
mysql_get_server_info
22.9.8.7.17. MysqlndUhConnection::getServerStatistics

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getServerStatistics

    Gets the current system status

Description

public string MysqlndUhConnection::getServerStatistics(mysqlnd_connection connection);

Gets the current system status.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The system status message.

Examples

Example 22.339. MysqlndUhConnection::getServerStatisticsexample

<?phpclass proxy extends MysqlndUhConnection { public function getServerStatistics($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getServerStatistics($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump(mysqli_stat($mysqli));?> 

The above example will output:

proxy::getServerStatistics(array (  0 => NULL,))proxy::getServerStatistics returns 'Uptime: 2059995  Threads: 1  Questions: 126157Slow queries: 0  Opens: 6377  Flush tables: 1  Open tables: 18  Queries per secondavg: 0.61'string(140) "Uptime: 2059995  Threads: 1  Questions: 126157  Slow queries: 0  Opens: 6377  Flush tables: 1  Open tables: 18  Queries per second avg: 0.61"

See Also

mysqlnd_uh_set_connection_proxy
mysqli_stat
mysql_stat
22.9.8.7.18. MysqlndUhConnection::getServerVersion

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getServerVersion

    Returns the version of the MySQL server as an integer

Description

public int MysqlndUhConnection::getServerVersion(mysqlnd_connection connection);

Returns the version of the MySQL server as an integer.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The MySQL version.

Examples

Example 22.340. MysqlndUhConnection::getServerVersionexample

<?phpclass proxy extends MysqlndUhConnection { public function getServerVersion($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getServerVersion($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->server_version);?> 

The above example will output:

proxy::getServerVersion(array (  0 => NULL,))proxy::getServerVersion returns 50145int(50145)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_get_server_version
mysql_get_server_version
22.9.8.7.19. MysqlndUhConnection::getSqlstate

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getSqlstate

    Returns the SQLSTATE error from previous MySQL operation

Description

public string MysqlndUhConnection::getSqlstate(mysqlnd_connection connection);

Returns the SQLSTATE error from previous MySQL operation.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

The SQLSTATE code.

Examples

Example 22.341. MysqlndUhConnection::getSqlstateexample

<?phpclass proxy extends MysqlndUhConnection { public function getSqlstate($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getSqlstate($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->sqlstate);$mysqli->query("AN_INVALID_REQUEST_TO_PROVOKE_AN_ERROR");var_dump($mysqli->sqlstate);?> 

The above example will output:

proxy::getSqlstate(array (  0 => NULL,))proxy::getSqlstate returns '00000'string(5) "00000"proxy::getSqlstate(array (  0 => NULL,))proxy::getSqlstate returns '42000'string(5) "42000"

See Also

mysqlnd_uh_set_connection_proxy
mysqli_sql_state
22.9.8.7.20. MysqlndUhConnection::getStatistics

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getStatistics

    Returns statistics about the client connection.

Description

public array MysqlndUhConnection::getStatistics(mysqlnd_connection connection);

Returns statistics about the client connection.

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Connection statistics collected by mysqlnd.

Examples

Example 22.342. MysqlndUhConnection::getStatisticsexample

<?phpclass proxy extends MysqlndUhConnection { public function getStatistics($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getStatistics($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->get_connection_stats());?> 

The above example will output:

proxy::getStatistics(array (  0 => NULL,))proxy::getStatistics returns array (  'bytes_sent' => '73',  'bytes_received' => '77',  'packets_sent' => '2',  'packets_received' => '2',  'protocol_overhead_in' => '8',  'protocol_overhead_out' => '8',  'bytes_received_ok_packet' => '0',  'bytes_received_eof_packet' => '0',  'bytes_received_rset_header_packet' => '0',  'bytes_received_rset_field_meta_packet' => '0',  'bytes_received_rset_row_packet' => '0',  'bytes_received_prepare_response_packet' => '0',  'bytes_received_change_user_packet' => '0',  'packets_sent_command' => '0',  'packets_received_ok' => '0',  'packets_received_eof' => '0',  'packets_received_rset_header' => '0',  'packets_received_rset_field_meta' => '0',  'packets_received_rset_row' => '0',  'packets_received_prepare_response' => '0',  'packets_received_change_user' => '0',  'result_set_queries' => '0',  'non_result_set_queries' => '0',  'no_index_used' => '0',  'bad_index_used' => '0',  'slow_queries' => '0',  'buffered_sets' => '0',  'unbuffered_sets' => '0',  'ps_buffered_sets' => '0',  'ps_unbuffered_sets' => '0',  'flushed_normal_sets' => '0',  'flushed_ps_sets' => '0',  'ps_prepared_never_executed' => '0',  'ps_prepared_once_executed' => '0',  'rows_fetched_from_server_normal' => '0',  'rows_fetched_from_server_ps' => '0',  'rows_buffered_from_client_normal' => '0',  'rows_buffered_from_client_ps' => '0',  'rows_fetched_from_client_normal_buffered' => '0',  'rows_fetched_from_client_normal_unbuffered' => '0',  'rows_fetched_from_client_ps_buffered' => '0',  'rows_fetched_from_client_ps_unbuffered' => '0',  'rows_fetched_from_client_ps_cursor' => '0',  'rows_affected_normal' => '0',  'rows_affected_ps' => '0',  'rows_skipped_normal' => '0',  'rows_skipped_ps' => '0',  'copy_on_write_saved' => '0',  'copy_on_write_performed' => '0',  'command_buffer_too_small' => '0',  'connect_success' => '1',  'connect_failure' => '0',  'connection_reused' => '0',  'reconnect' => '0',  'pconnect_success' => '0',  'active_connections' => '1',  'active_persistent_connections' => '0',  'explicit_close' => '0',  'implicit_close' => '0',  'disconnect_close' => '0',  'in_middle_of_command_close' => '0',  'explicit_free_result' => '0',  'implicit_free_result' => '0',  'explicit_stmt_close' => '0',  'implicit_stmt_close' => '0',  'mem_emalloc_count' => '0',  'mem_emalloc_amount' => '0',  'mem_ecalloc_count' => '0',  'mem_ecalloc_amount' => '0',  'mem_erealloc_count' => '0',  'mem_erealloc_amount' => '0',  'mem_efree_count' => '0',  'mem_efree_amount' => '0',  'mem_malloc_count' => '0',  'mem_malloc_amount' => '0',  'mem_calloc_count' => '0',  'mem_calloc_amount' => '0',  'mem_realloc_count' => '0',  'mem_realloc_amount' => '0',  'mem_free_count' => '0',  'mem_free_amount' => '0',  'mem_estrndup_count' => '0',  'mem_strndup_count' => '0',  'mem_estndup_count' => '0',  'mem_strdup_count' => '0',  'proto_text_fetched_null' => '0',  'proto_text_fetched_bit' => '0',  'proto_text_fetched_tinyint' => '0',  'proto_text_fetched_short' => '0',  'proto_text_fetched_int24' => '0',  'proto_text_fetched_int' => '0',  'proto_text_fetched_bigint' => '0',  'proto_text_fetched_decimal' => '0',  'proto_text_fetched_float' => '0',  'proto_text_fetched_double' => '0',  'proto_text_fetched_date' => '0',  'proto_text_fetched_year' => '0',  'proto_text_fetched_time' => '0',  'proto_text_fetched_datetime' => '0',  'proto_text_fetched_timestamp' => '0',  'proto_text_fetched_string' => '0',  'proto_text_fetched_blob' => '0',  'proto_text_fetched_enum' => '0',  'proto_text_fetched_set' => '0',  'proto_text_fetched_geometry' => '0',  'proto_text_fetched_other' => '0',  'proto_binary_fetched_null' => '0',  'proto_binary_fetched_bit' => '0',  'proto_binary_fetched_tinyint' => '0',  'proto_binary_fetched_short' => '0',  'proto_binary_fetched_int24' => '0',  'proto_binary_fetched_int' => '0',  'proto_binary_fetched_bigint' => '0',  'proto_binary_fetched_decimal' => '0',  'proto_binary_fetched_float' => '0',  'proto_binary_fetched_double' => '0',  'proto_binary_fetched_date' => '0',  'proto_binary_fetched_year' => '0',  'proto_binary_fetched_time' => '0',  'proto_binary_fetched_datetime' => '0',  'proto_binary_fetched_timestamp' => '0',  'proto_binary_fetched_string' => '0',  'proto_binary_fetched_blob' => '0',  'proto_binary_fetched_enum' => '0',  'proto_binary_fetched_set' => '0',  'proto_binary_fetched_geometry' => '0',  'proto_binary_fetched_other' => '0',  'init_command_executed_count' => '0',  'init_command_failed_count' => '0',  'com_quit' => '0',  'com_init_db' => '0',  'com_query' => '0',  'com_field_list' => '0',  'com_create_db' => '0',  'com_drop_db' => '0',  'com_refresh' => '0',  'com_shutdown' => '0',  'com_statistics' => '0',  'com_process_info' => '0',  'com_connect' => '0',  'com_process_kill' => '0',  'com_debug' => '0',  'com_ping' => '0',  'com_time' => '0',  'com_delayed_insert' => '0',  'com_change_user' => '0',  'com_binlog_dump' => '0',  'com_table_dump' => '0',  'com_connect_out' => '0',  'com_register_slave' => '0',  'com_stmt_prepare' => '0',  'com_stmt_execute' => '0',  'com_stmt_send_long_data' => '0',  'com_stmt_close' => '0',  'com_stmt_reset' => '0',  'com_stmt_set_option' => '0',  'com_stmt_fetch' => '0',  'com_deamon' => '0',  'bytes_received_real_data_normal' => '0',  'bytes_received_real_data_ps' => '0',)array(160) {  ["bytes_sent"]=>  string(2) "73"  ["bytes_received"]=>  string(2) "77"  ["packets_sent"]=>  string(1) "2"  ["packets_received"]=>  string(1) "2"  ["protocol_overhead_in"]=>  string(1) "8"  ["protocol_overhead_out"]=>  string(1) "8"  ["bytes_received_ok_packet"]=>  string(1) "0"  ["bytes_received_eof_packet"]=>  string(1) "0"  ["bytes_received_rset_header_packet"]=>  string(1) "0"  ["bytes_received_rset_field_meta_packet"]=>  string(1) "0"  ["bytes_received_rset_row_packet"]=>  string(1) "0"  ["bytes_received_prepare_response_packet"]=>  string(1) "0"  ["bytes_received_change_user_packet"]=>  string(1) "0"  ["packets_sent_command"]=>  string(1) "0"  ["packets_received_ok"]=>  string(1) "0"  ["packets_received_eof"]=>  string(1) "0"  ["packets_received_rset_header"]=>  string(1) "0"  ["packets_received_rset_field_meta"]=>  string(1) "0"  ["packets_received_rset_row"]=>  string(1) "0"  ["packets_received_prepare_response"]=>  string(1) "0"  ["packets_received_change_user"]=>  string(1) "0"  ["result_set_queries"]=>  string(1) "0"  ["non_result_set_queries"]=>  string(1) "0"  ["no_index_used"]=>  string(1) "0"  ["bad_index_used"]=>  string(1) "0"  ["slow_queries"]=>  string(1) "0"  ["buffered_sets"]=>  string(1) "0"  ["unbuffered_sets"]=>  string(1) "0"  ["ps_buffered_sets"]=>  string(1) "0"  ["ps_unbuffered_sets"]=>  string(1) "0"  ["flushed_normal_sets"]=>  string(1) "0"  ["flushed_ps_sets"]=>  string(1) "0"  ["ps_prepared_never_executed"]=>  string(1) "0"  ["ps_prepared_once_executed"]=>  string(1) "0"  ["rows_fetched_from_server_normal"]=>  string(1) "0"  ["rows_fetched_from_server_ps"]=>  string(1) "0"  ["rows_buffered_from_client_normal"]=>  string(1) "0"  ["rows_buffered_from_client_ps"]=>  string(1) "0"  ["rows_fetched_from_client_normal_buffered"]=>  string(1) "0"  ["rows_fetched_from_client_normal_unbuffered"]=>  string(1) "0"  ["rows_fetched_from_client_ps_buffered"]=>  string(1) "0"  ["rows_fetched_from_client_ps_unbuffered"]=>  string(1) "0"  ["rows_fetched_from_client_ps_cursor"]=>  string(1) "0"  ["rows_affected_normal"]=>  string(1) "0"  ["rows_affected_ps"]=>  string(1) "0"  ["rows_skipped_normal"]=>  string(1) "0"  ["rows_skipped_ps"]=>  string(1) "0"  ["copy_on_write_saved"]=>  string(1) "0"  ["copy_on_write_performed"]=>  string(1) "0"  ["command_buffer_too_small"]=>  string(1) "0"  ["connect_success"]=>  string(1) "1"  ["connect_failure"]=>  string(1) "0"  ["connection_reused"]=>  string(1) "0"  ["reconnect"]=>  string(1) "0"  ["pconnect_success"]=>  string(1) "0"  ["active_connections"]=>  string(1) "1"  ["active_persistent_connections"]=>  string(1) "0"  ["explicit_close"]=>  string(1) "0"  ["implicit_close"]=>  string(1) "0"  ["disconnect_close"]=>  string(1) "0"  ["in_middle_of_command_close"]=>  string(1) "0"  ["explicit_free_result"]=>  string(1) "0"  ["implicit_free_result"]=>  string(1) "0"  ["explicit_stmt_close"]=>  string(1) "0"  ["implicit_stmt_close"]=>  string(1) "0"  ["mem_emalloc_count"]=>  string(1) "0"  ["mem_emalloc_amount"]=>  string(1) "0"  ["mem_ecalloc_count"]=>  string(1) "0"  ["mem_ecalloc_amount"]=>  string(1) "0"  ["mem_erealloc_count"]=>  string(1) "0"  ["mem_erealloc_amount"]=>  string(1) "0"  ["mem_efree_count"]=>  string(1) "0"  ["mem_efree_amount"]=>  string(1) "0"  ["mem_malloc_count"]=>  string(1) "0"  ["mem_malloc_amount"]=>  string(1) "0"  ["mem_calloc_count"]=>  string(1) "0"  ["mem_calloc_amount"]=>  string(1) "0"  ["mem_realloc_count"]=>  string(1) "0"  ["mem_realloc_amount"]=>  string(1) "0"  ["mem_free_count"]=>  string(1) "0"  ["mem_free_amount"]=>  string(1) "0"  ["mem_estrndup_count"]=>  string(1) "0"  ["mem_strndup_count"]=>  string(1) "0"  ["mem_estndup_count"]=>  string(1) "0"  ["mem_strdup_count"]=>  string(1) "0"  ["proto_text_fetched_null"]=>  string(1) "0"  ["proto_text_fetched_bit"]=>  string(1) "0"  ["proto_text_fetched_tinyint"]=>  string(1) "0"  ["proto_text_fetched_short"]=>  string(1) "0"  ["proto_text_fetched_int24"]=>  string(1) "0"  ["proto_text_fetched_int"]=>  string(1) "0"  ["proto_text_fetched_bigint"]=>  string(1) "0"  ["proto_text_fetched_decimal"]=>  string(1) "0"  ["proto_text_fetched_float"]=>  string(1) "0"  ["proto_text_fetched_double"]=>  string(1) "0"  ["proto_text_fetched_date"]=>  string(1) "0"  ["proto_text_fetched_year"]=>  string(1) "0"  ["proto_text_fetched_time"]=>  string(1) "0"  ["proto_text_fetched_datetime"]=>  string(1) "0"  ["proto_text_fetched_timestamp"]=>  string(1) "0"  ["proto_text_fetched_string"]=>  string(1) "0"  ["proto_text_fetched_blob"]=>  string(1) "0"  ["proto_text_fetched_enum"]=>  string(1) "0"  ["proto_text_fetched_set"]=>  string(1) "0"  ["proto_text_fetched_geometry"]=>  string(1) "0"  ["proto_text_fetched_other"]=>  string(1) "0"  ["proto_binary_fetched_null"]=>  string(1) "0"  ["proto_binary_fetched_bit"]=>  string(1) "0"  ["proto_binary_fetched_tinyint"]=>  string(1) "0"  ["proto_binary_fetched_short"]=>  string(1) "0"  ["proto_binary_fetched_int24"]=>  string(1) "0"  ["proto_binary_fetched_int"]=>  string(1) "0"  ["proto_binary_fetched_bigint"]=>  string(1) "0"  ["proto_binary_fetched_decimal"]=>  string(1) "0"  ["proto_binary_fetched_float"]=>  string(1) "0"  ["proto_binary_fetched_double"]=>  string(1) "0"  ["proto_binary_fetched_date"]=>  string(1) "0"  ["proto_binary_fetched_year"]=>  string(1) "0"  ["proto_binary_fetched_time"]=>  string(1) "0"  ["proto_binary_fetched_datetime"]=>  string(1) "0"  ["proto_binary_fetched_timestamp"]=>  string(1) "0"  ["proto_binary_fetched_string"]=>  string(1) "0"  ["proto_binary_fetched_blob"]=>  string(1) "0"  ["proto_binary_fetched_enum"]=>  string(1) "0"  ["proto_binary_fetched_set"]=>  string(1) "0"  ["proto_binary_fetched_geometry"]=>  string(1) "0"  ["proto_binary_fetched_other"]=>  string(1) "0"  ["init_command_executed_count"]=>  string(1) "0"  ["init_command_failed_count"]=>  string(1) "0"  ["com_quit"]=>  string(1) "0"  ["com_init_db"]=>  string(1) "0"  ["com_query"]=>  string(1) "0"  ["com_field_list"]=>  string(1) "0"  ["com_create_db"]=>  string(1) "0"  ["com_drop_db"]=>  string(1) "0"  ["com_refresh"]=>  string(1) "0"  ["com_shutdown"]=>  string(1) "0"  ["com_statistics"]=>  string(1) "0"  ["com_process_info"]=>  string(1) "0"  ["com_connect"]=>  string(1) "0"  ["com_process_kill"]=>  string(1) "0"  ["com_debug"]=>  string(1) "0"  ["com_ping"]=>  string(1) "0"  ["com_time"]=>  string(1) "0"  ["com_delayed_insert"]=>  string(1) "0"  ["com_change_user"]=>  string(1) "0"  ["com_binlog_dump"]=>  string(1) "0"  ["com_table_dump"]=>  string(1) "0"  ["com_connect_out"]=>  string(1) "0"  ["com_register_slave"]=>  string(1) "0"  ["com_stmt_prepare"]=>  string(1) "0"  ["com_stmt_execute"]=>  string(1) "0"  ["com_stmt_send_long_data"]=>  string(1) "0"  ["com_stmt_close"]=>  string(1) "0"  ["com_stmt_reset"]=>  string(1) "0"  ["com_stmt_set_option"]=>  string(1) "0"  ["com_stmt_fetch"]=>  string(1) "0"  ["com_deamon"]=>  string(1) "0"  ["bytes_received_real_data_normal"]=>  string(1) "0"  ["bytes_received_real_data_ps"]=>  string(1) "0"}

See Also

mysqlnd_uh_set_connection_proxy
mysqli_get_connection_stats
22.9.8.7.21. MysqlndUhConnection::getThreadId

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getThreadId

    Returns the thread ID for the current connection

Description

public int MysqlndUhConnection::getThreadId(mysqlnd_connection connection);

Returns the thread ID for the current connection.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Connection thread id.

Examples

Example 22.343. MysqlndUhConnection::getThreadIdexample

<?phpclass proxy extends MysqlndUhConnection { public function getThreadId($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getThreadId($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->thread_id);?> 

The above example will output:

proxy::getThreadId(array (  0 => NULL,))proxy::getThreadId returns 27646int(27646)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_thread_id
mysql_thread_id
22.9.8.7.22. MysqlndUhConnection::getWarningCount

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::getWarningCount

    Returns the number of warnings from the last query for the given link

Description

public int MysqlndUhConnection::getWarningCount(mysqlnd_connection connection);

Returns the number of warnings from the last query for the given link.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Number of warnings.

Examples

Example 22.344. MysqlndUhConnection::getWarningCountexample

<?phpclass proxy extends MysqlndUhConnection { public function getWarningCount($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::getWarningCount($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");var_dump($mysqli->warning_count);?> 

The above example will output:

proxy::getWarningCount(array (  0 => NULL,))proxy::getWarningCount returns 0int(0)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_warning_count
22.9.8.7.23. MysqlndUhConnection::init

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::init

    Initialize mysqlnd connection

Description

public bool MysqlndUhConnection::init(mysqlnd_connection connection);

Initialize mysqlnd connection. This is an mysqlnd internal call to initialize the connection object.

Note

Failing to call the parent implementation may cause memory leaks or crash PHP. This is not considered a bug. Please, keep in mind that the mysqlnd library functions have never been designed to be exposed to the user space.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.345. MysqlndUhConnection::initexample

<?phpclass proxy extends MysqlndUhConnection { public function init($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::init($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");?> 

The above example will output:

proxy::init(array (  0 => NULL,))proxy::init returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.24. MysqlndUhConnection::killConnection

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::killConnection

    Asks the server to kill a MySQL thread

Description

public bool MysqlndUhConnection::killConnection(mysqlnd_connection connection,
int pid);

Asks the server to kill a MySQL thread.

Parameters

connection

Mysqlnd connection handle. Do not modify!

pid

Thread Id of the connection to be killed.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.346. MysqlndUhConnection::killexample

<?phpclass proxy extends MysqlndUhConnection { public function killConnection($res, $pid) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::killConnection($res, $pid);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->kill($mysqli->thread_id);?> 

The above example will output:

proxy::killConnection(array (  0 => NULL,  1 => 27650,))proxy::killConnection returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_kill
22.9.8.7.25. MysqlndUhConnection::listFields

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::listFields

    List MySQL table fields

Description

public array MysqlndUhConnection::listFields(mysqlnd_connection connection,
string table,
string achtung_wild);

List MySQL table fields.

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

connection

Mysqlnd connection handle. Do not modify!

table

The name of the table that's being queried.

pattern

Name pattern.

Return Values

Examples

Example 22.347. MysqlndUhConnection::listFieldsexample

<?phpclass proxy extends MysqlndUhConnection { public function listFields($res, $table, $pattern) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::listFields($res, $table, $pattern);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysql = mysql_connect("localhost", "root", "");mysql_select_db("test", $mysql);mysql_query("DROP TABLE IF EXISTS test_a", $mysql);mysql_query("CREATE TABLE test_a(id INT, col1 VARCHAR(255))", $mysql);$res = mysql_list_fields("test", "test_a", $mysql);printf("num_rows = %d\n", mysql_num_rows($res));while ($row = mysql_fetch_assoc($res)) var_dump($row);?> 

The above example will output:

proxy::listFields(array (  0 => NULL,  1 => 'test_a',  2 => '',))proxy::listFields returns NULLnum_rows = 0

See Also

mysqlnd_uh_set_connection_proxy
mysql_list_fields
22.9.8.7.26. MysqlndUhConnection::listMethod

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::listMethod

    Wrapper for assorted list commands

Description

public void MysqlndUhConnection::listMethod(mysqlnd_connection connection,
string query,
string achtung_wild,
string par1);

Wrapper for assorted list commands.

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

connection

Mysqlnd connection handle. Do not modify!

query

SHOW command to be executed.

achtung_wild

par1

Return Values

Return Values

TODO

Examples

Example 22.348. MysqlndUhConnection::listMethodexample

<?phpclass proxy extends MysqlndUhConnection { public function listMethod($res, $query, $pattern, $par1) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::listMethod($res, $query, $pattern, $par1);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysql = mysql_connect("localhost", "root", "");$res = mysql_list_dbs($mysql);printf("num_rows = %d\n", mysql_num_rows($res));while ($row = mysql_fetch_assoc($res)) var_dump($row);?> 

The above example will output:

proxy::listMethod(array (  0 => NULL,  1 => 'SHOW DATABASES',  2 => '',  3 => '',))proxy::listMethod returns NULLnum_rows = 6array(1) {  ["Database"]=>  string(18) "information_schema"}array(1) {  ["Database"]=>  string(5) "mysql"}array(1) {  ["Database"]=>  string(8) "oxid_new"}array(1) {  ["Database"]=>  string(7) "phptest"}array(1) {  ["Database"]=>  string(7) "pushphp"}array(1) {  ["Database"]=>  string(4) "test"}

See Also

mysqlnd_uh_set_connection_proxy
mysql_list_dbs
22.9.8.7.27. MysqlndUhConnection::moreResults

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::moreResults

    Check if there are any more query results from a multi query

Description

public bool MysqlndUhConnection::moreResults(mysqlnd_connection connection);

Check if there are any more query results from a multi query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.349. MysqlndUhConnection::moreResultsexample

<?phpclass proxy extends MysqlndUhConnection { public function moreResults($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::moreResults($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->multi_query("SELECT 1 AS _one; SELECT 2 AS _two");do {  $res = $mysqli->store_result();  var_dump($res->fetch_assoc());  printf("%s\n", str_repeat("-", 40));} while ($mysqli->more_results() && $mysqli->next_result());?> 

The above example will output:

array(1) {  ["_one"]=>  string(1) "1"}----------------------------------------proxy::moreResults(array (  0 => NULL,))proxy::moreResults returns trueproxy::moreResults(array (  0 => NULL,))proxy::moreResults returns truearray(1) {  ["_two"]=>  string(1) "2"}----------------------------------------proxy::moreResults(array (  0 => NULL,))proxy::moreResults returns false

See Also

mysqlnd_uh_set_connection_proxy
mysqli_more_results
22.9.8.7.28. MysqlndUhConnection::nextResult

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::nextResult

    Prepare next result from multi_query

Description

public bool MysqlndUhConnection::nextResult(mysqlnd_connection connection);

Prepare next result from multi_query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.350. MysqlndUhConnection::nextResultexample

<?phpclass proxy extends MysqlndUhConnection { public function nextResult($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::nextResult($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->multi_query("SELECT 1 AS _one; SELECT 2 AS _two");do {  $res = $mysqli->store_result();  var_dump($res->fetch_assoc());  printf("%s\n", str_repeat("-", 40));} while ($mysqli->more_results() && $mysqli->next_result());?> 

The above example will output:

array(1) {  ["_one"]=>  string(1) "1"}----------------------------------------proxy::nextResult(array (  0 => NULL,))proxy::nextResult returns truearray(1) {  ["_two"]=>  string(1) "2"}----------------------------------------

See Also

mysqlnd_uh_set_connection_proxy
mysqli_next_result
22.9.8.7.29. MysqlndUhConnection::ping

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::ping

    Pings a server connection, or tries to reconnect if the connection has gone down

Description

public bool MysqlndUhConnection::ping(mysqlnd_connection connection);

Pings a server connection, or tries to reconnect if the connection has gone down.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.351. MysqlndUhConnection::pingexample

<?phpclass proxy extends MysqlndUhConnection { public function ping($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::ping($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->ping();?> 

The above example will output:

proxy::ping(array (  0 => NULL,))proxy::ping returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_ping
mysql_ping
22.9.8.7.30. MysqlndUhConnection::query

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::query

    Performs a query on the database

Description

public bool MysqlndUhConnection::query(mysqlnd_connection connection,
string query);

Performs a query on the database (COM_QUERY).

Parameters

connection

Mysqlnd connection handle. Do not modify!

query

The query string.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.352. MysqlndUhConnection::queryexample

<?phpclass proxy extends MysqlndUhConnection { public function query($res, $query) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $query = "SELECT 'How about query rewriting?'";  $ret = parent::query($res, $query);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$res = $mysqli->query("SELECT 'Welcome mysqlnd_uh!' FROM DUAL");var_dump($res->fetch_assoc());?> 

The above example will output:

proxy::query(array (  0 => NULL,  1 => 'SELECT \'Welcome mysqlnd_uh!\' FROM DUAL',))proxy::query returns truearray(1) {  ["How about query rewriting?"]=>  string(26) "How about query rewriting?"}

See Also

mysqlnd_uh_set_connection_proxy
mysqli_query
mysql_query
22.9.8.7.31. MysqlndUhConnection::queryReadResultsetHeader

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::queryReadResultsetHeader

    Read a result set header

Description

public bool MysqlndUhConnection::queryReadResultsetHeader(mysqlnd_connection connection,
mysqlnd_statement mysqlnd_stmt);

Read a result set header.

Parameters

connection

Mysqlnd connection handle. Do not modify!

mysqlnd_stmt

Mysqlnd statement handle. Do not modify! Set to NULL , if function is not used in the context of a prepared statement.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.353. MysqlndUhConnection::queryReadResultsetHeaderexample

<?phpclass proxy extends MysqlndUhConnection { public function queryReadResultsetHeader($res, $stmt) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::queryReadResultsetHeader($res, $stmt);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$res = $mysqli->query("SELECT 'Welcome mysqlnd_uh!' FROM DUAL");var_dump($res->fetch_assoc());?> 

The above example will output:

proxy::queryReadResultsetHeader(array (  0 => NULL,  1 => NULL,))proxy::queryReadResultsetHeader returns truearray(1) {  ["Welcome mysqlnd_uh!"]=>  string(19) "Welcome mysqlnd_uh!"}

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.32. MysqlndUhConnection::reapQuery

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::reapQuery

    Get result from async query

Description

public bool MysqlndUhConnection::reapQuery(mysqlnd_connection connection);

Get result from async query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.354. MysqlndUhConnection::reapQueryexample

<?phpclass proxy extends MysqlndUhConnection { public function reapQuery($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::reapQuery($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$conn1 = new mysqli("localhost", "root", "", "test");$conn2 = new mysqli("localhost", "root", "", "test");$conn1->query("SELECT 1 as 'one', SLEEP(1) AS _sleep FROM DUAL", MYSQLI_ASYNC |  MYSQLI_USE_RESULT);$conn2->query("SELECT 1.1 as 'one dot one' FROM DUAL", MYSQLI_ASYNC |  MYSQLI_USE_RESULT);$links = array( $conn1->thread_id => array('link' => $conn1, 'processed' => false), $conn2->thread_id => array('link' => $conn2, 'processed' => false));$saved_errors = array();do { $poll_links = $poll_errors = $poll_reject = array(); foreach ($links as $thread_id => $link) {  if (!$link['processed']) {   $poll_links[] = $link['link'];   $poll_errors[] = $link['link'];   $poll_reject[] = $link['link'];  } } if (0 == count($poll_links))  break; if (0 == ($num_ready = mysqli_poll($poll_links, $poll_errors, $poll_reject, 0, 200000)))  continue; if (!empty($poll_errors)) {  die(var_dump($poll_errors)); } foreach ($poll_links as $link) {  $thread_id = mysqli_thread_id($link);  $links[$thread_id]['processed'] = true;  if (is_object($res = mysqli_reap_async_query($link))) {   // result set object   while ($row = mysqli_fetch_assoc($res)) { // eat up all results var_dump($row);   }   mysqli_free_result($res);  } else {   // either there is no result (no SELECT) or there is an error   if (mysqli_errno($link) > 0) { $saved_errors[$thread_id] = mysqli_errno($link); printf("'%s' caused %d\n", $links[$thread_id]['query'], mysqli_errno($link));   }  } }} while (true);?> 

The above example will output:

proxy::reapQuery(array (  0 => NULL,))proxy::reapQuery returns truearray(1) {  ["one dot one"]=>  string(3) "1.1"}proxy::reapQuery(array (  0 => NULL,))proxy::reapQuery returns truearray(2) {  ["one"]=>  string(1) "1"  ["_sleep"]=>  string(1) "0"}

See Also

mysqlnd_uh_set_connection_proxy
mysqli_real_async_query
22.9.8.7.33. MysqlndUhConnection::refreshServer

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::refreshServer

    Flush or reset tables and caches

Description

public bool MysqlndUhConnection::refreshServer(mysqlnd_connection connection,
int options);

Flush or reset tables and caches.

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

connection

Mysqlnd connection handle. Do not modify!

options

What to refresh.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.355. MysqlndUhConnection::refreshServerexample

<?phpclass proxy extends MysqlndUhConnection { public function refreshServer($res, $option) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::refreshServer($res, $option);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");mysqli_refresh($mysqli, 1);?> 

The above example will output:

proxy::refreshServer(array (  0 => NULL,  1 => 1,))proxy::refreshServer returns false

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.34. MysqlndUhConnection::restartPSession

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::restartPSession

    Restart a persistent mysqlnd connection

Description

public bool MysqlndUhConnection::restartPSession(mysqlnd_connection connection);

Restart a persistent mysqlnd connection.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.356. MysqlndUhConnection::restartPSessionexample

<?phpclass proxy extends MysqlndUhConnection { public function ping($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::ping($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->ping();?> 

The above example will output:

proxy::restartPSession(array (  0 => NULL,))proxy::restartPSession returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.35. MysqlndUhConnection::selectDb

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::selectDb

    Selects the default database for database queries

Description

public bool MysqlndUhConnection::selectDb(mysqlnd_connection connection,
string database);

Selects the default database for database queries.

Parameters

connection

Mysqlnd connection handle. Do not modify!

database

The database name.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.357. MysqlndUhConnection::selectDbexample

<?phpclass proxy extends MysqlndUhConnection { public function selectDb($res, $database) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::selectDb($res, $database);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->select_db("mysql");?> 

The above example will output:

proxy::selectDb(array (  0 => NULL,  1 => 'mysql',))proxy::selectDb returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_select_db
mysql_select_db
22.9.8.7.36. MysqlndUhConnection::sendClose

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::sendClose

    Sends a close command to MySQL

Description

public bool MysqlndUhConnection::sendClose(mysqlnd_connection connection);

Sends a close command to MySQL.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.358. MysqlndUhConnection::sendCloseexample

<?phpclass proxy extends MysqlndUhConnection { public function sendClose($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::sendClose($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->close();?> 

The above example will output:

proxy::sendClose(array (  0 => NULL,))proxy::sendClose returns trueproxy::sendClose(array (  0 => NULL,))proxy::sendClose returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.37. MysqlndUhConnection::sendQuery

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::sendQuery

    Sends a query to MySQL

Description

public bool MysqlndUhConnection::sendQuery(mysqlnd_connection connection,
string query);

Sends a query to MySQL.

Parameters

connection

Mysqlnd connection handle. Do not modify!

query

The query string.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.359. MysqlndUhConnection::sendQueryexample

<?phpclass proxy extends MysqlndUhConnection { public function sendQuery($res, $query) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::sendQuery($res, $query);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("SELECT 1");?> 

The above example will output:

proxy::sendQuery(array (  0 => NULL,  1 => 'SELECT 1',))proxy::sendQuery returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.38. MysqlndUhConnection::serverDumpDebugInformation

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::serverDumpDebugInformation

    Dump debugging information into the log for the MySQL server

Description

public bool MysqlndUhConnection::serverDumpDebugInformation(mysqlnd_connection connection);

Dump debugging information into the log for the MySQL server.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.360. MysqlndUhConnection::serverDumpDebugInformationexample

<?phpclass proxy extends MysqlndUhConnection { public function serverDumpDebugInformation($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::serverDumpDebugInformation($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->dump_debug_info();?> 

The above example will output:

proxy::serverDumpDebugInformation(array (  0 => NULL,))proxy::serverDumpDebugInformation returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_dump_debug_info
22.9.8.7.39. MysqlndUhConnection::setAutocommit

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::setAutocommit

    Turns on or off auto-committing database modifications

Description

public bool MysqlndUhConnection::setAutocommit(mysqlnd_connection connection,
int mode);

Turns on or off auto-committing database modifications

Parameters

connection

Mysqlnd connection handle. Do not modify!

mode

Whether to turn on auto-commit or not.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.361. MysqlndUhConnection::setAutocommitexample

<?phpclass proxy extends MysqlndUhConnection { public function setAutocommit($res, $mode) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::setAutocommit($res, $mode);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->autocommit(false);$mysqli->autocommit(true);?> 

The above example will output:

proxy::setAutocommit(array (  0 => NULL,  1 => 0,))proxy::setAutocommit returns trueproxy::setAutocommit(array (  0 => NULL,  1 => 1,))proxy::setAutocommit returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_autocommit
22.9.8.7.40. MysqlndUhConnection::setCharset

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::setCharset

    Sets the default client character set

Description

public bool MysqlndUhConnection::setCharset(mysqlnd_connection connection,
string charset);

Sets the default client character set.

Parameters

connection

Mysqlnd connection handle. Do not modify!

charset

The charset to be set as default.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.362. MysqlndUhConnection::setCharsetexample

<?phpclass proxy extends MysqlndUhConnection { public function setCharset($res, $charset) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::setCharset($res, $charset);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->set_charset("latin1");?> 

The above example will output:

proxy::setCharset(array (  0 => NULL,  1 => 'latin1',))proxy::setCharset returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_set_charset
22.9.8.7.41. MysqlndUhConnection::setClientOption

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::setClientOption

    Sets a client option

Description

public bool MysqlndUhConnection::setClientOption(mysqlnd_connection connection,
int option,
int value);

Sets a client option.

Parameters

connection

Mysqlnd connection handle. Do not modify!

option

The option to be set.

value

Optional option value, if required.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.363. MysqlndUhConnection::setClientOptionexample

<?phpfunction client_option_to_string($option) { static $mapping = array(  MYSQLND_UH_MYSQLND_OPTION_OPT_CONNECT_TIMEOUT =>   "MYSQLND_UH_MYSQLND_OPTION_OPT_CONNECT_TIMEOUT",  MYSQLND_UH_MYSQLND_OPTION_OPT_COMPRESS => "MYSQLND_UH_MYSQLND_OPTION_OPT_COMPRESS",  MYSQLND_UH_MYSQLND_OPTION_OPT_NAMED_PIPE => "MYSQLND_UH_MYSQLND_OPTION_OPT_NAMED_PIPE",  MYSQLND_UH_MYSQLND_OPTION_INIT_COMMAND => "MYSQLND_UH_MYSQLND_OPTION_INIT_COMMAND",  MYSQLND_UH_MYSQLND_READ_DEFAULT_FILE => "MYSQLND_UH_MYSQLND_READ_DEFAULT_FILE",  MYSQLND_UH_MYSQLND_READ_DEFAULT_GROUP => "MYSQLND_UH_MYSQLND_READ_DEFAULT_GROUP",  MYSQLND_UH_MYSQLND_SET_CHARSET_DIR => "MYSQLND_UH_MYSQLND_SET_CHARSET_DIR",  MYSQLND_UH_MYSQLND_SET_CHARSET_NAME => "MYSQLND_UH_MYSQLND_SET_CHARSET_NAME",  MYSQLND_UH_MYSQLND_OPT_LOCAL_INFILE => "MYSQLND_UH_MYSQLND_OPT_LOCAL_INFILE",  MYSQLND_UH_MYSQLND_OPT_PROTOCOL => "MYSQLND_UH_MYSQLND_OPT_PROTOCOL",  MYSQLND_UH_MYSQLND_SHARED_MEMORY_BASE_NAME =>   "MYSQLND_UH_MYSQLND_SHARED_MEMORY_BASE_NAME",  MYSQLND_UH_MYSQLND_OPT_READ_TIMEOUT => "MYSQLND_UH_MYSQLND_OPT_READ_TIMEOUT",  MYSQLND_UH_MYSQLND_OPT_WRITE_TIMEOUT => "MYSQLND_UH_MYSQLND_OPT_WRITE_TIMEOUT",  MYSQLND_UH_MYSQLND_OPT_USE_RESULT => "MYSQLND_UH_MYSQLND_OPT_USE_RESULT",  MYSQLND_UH_MYSQLND_OPT_USE_REMOTE_CONNECTION =>   "MYSQLND_UH_MYSQLND_OPT_USE_REMOTE_CONNECTION",  MYSQLND_UH_MYSQLND_OPT_USE_EMBEDDED_CONNECTION =>   "MYSQLND_UH_MYSQLND_OPT_USE_EMBEDDED_CONNECTION",  MYSQLND_UH_MYSQLND_OPT_GUESS_CONNECTION => "MYSQLND_UH_MYSQLND_OPT_GUESS_CONNECTION",  MYSQLND_UH_MYSQLND_SET_CLIENT_IP => "MYSQLND_UH_MYSQLND_SET_CLIENT_IP",  MYSQLND_UH_MYSQLND_SECURE_AUTH => "MYSQLND_UH_MYSQLND_SECURE_AUTH",  MYSQLND_UH_MYSQLND_REPORT_DATA_TRUNCATION => "MYSQLND_UH_MYSQLND_REPORT_DATA_TRUNCATION",  MYSQLND_UH_MYSQLND_OPT_RECONNECT => "MYSQLND_UH_MYSQLND_OPT_RECONNECT",  MYSQLND_UH_MYSQLND_OPT_SSL_VERIFY_SERVER_CERT =>   "MYSQLND_UH_MYSQLND_OPT_SSL_VERIFY_SERVER_CERT",  MYSQLND_UH_MYSQLND_OPT_NET_CMD_BUFFER_SIZE =>   "MYSQLND_UH_MYSQLND_OPT_NET_CMD_BUFFER_SIZE",  MYSQLND_UH_MYSQLND_OPT_NET_READ_BUFFER_SIZE =>   "MYSQLND_UH_MYSQLND_OPT_NET_READ_BUFFER_SIZE",  MYSQLND_UH_MYSQLND_OPT_SSL_KEY => "MYSQLND_UH_MYSQLND_OPT_SSL_KEY",  MYSQLND_UH_MYSQLND_OPT_SSL_CERT => "MYSQLND_UH_MYSQLND_OPT_SSL_CERT",  MYSQLND_UH_MYSQLND_OPT_SSL_CA => "MYSQLND_UH_MYSQLND_OPT_SSL_CA",  MYSQLND_UH_MYSQLND_OPT_SSL_CAPATH => "MYSQLND_UH_MYSQLND_OPT_SSL_CAPATH",  MYSQLND_UH_MYSQLND_OPT_SSL_CIPHER => "MYSQLND_UH_MYSQLND_OPT_SSL_CIPHER",  MYSQLND_UH_MYSQLND_OPT_SSL_PASSPHRASE => "MYSQLND_UH_MYSQLND_OPT_SSL_PASSPHRASE",  MYSQLND_UH_SERVER_OPTION_PLUGIN_DIR => "MYSQLND_UH_SERVER_OPTION_PLUGIN_DIR",  MYSQLND_UH_SERVER_OPTION_DEFAULT_AUTH => "MYSQLND_UH_SERVER_OPTION_DEFAULT_AUTH",  MYSQLND_UH_SERVER_OPTION_SET_CLIENT_IP => "MYSQLND_UH_SERVER_OPTION_SET_CLIENT_IP" ); if (version_compare(PHP_VERSION, '5.3.99-dev', '>')) {  $mapping[MYSQLND_UH_MYSQLND_OPT_MAX_ALLOWED_PACKET] =   "MYSQLND_UH_MYSQLND_OPT_MAX_ALLOWED_PACKET";  $mapping[MYSQLND_UH_MYSQLND_OPT_AUTH_PROTOCOL] = "MYSQLND_UH_MYSQLND_OPT_AUTH_PROTOCOL"; } if (defined("MYSQLND_UH_MYSQLND_OPT_INT_AND_FLOAT_NATIVE")) {  /* special mysqlnd build */  $mapping["MYSQLND_UH_MYSQLND_OPT_INT_AND_FLOAT_NATIVE"] =   "MYSQLND_UH_MYSQLND_OPT_INT_AND_FLOAT_NATIVE"; } return (isset($mapping[$option])) ? $mapping[$option] : 'unknown';}class proxy extends MysqlndUhConnection { public function setClientOption($res, $option, $value) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  printf("Option '%s' set to %s\n", client_option_to_string($option),   var_export($value, true));  $ret = parent::setClientOption($res, $option, $value);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");?> 

The above example will output:

proxy::setClientOption(array (  0 => NULL,  1 => 210,  2 => 3221225472,))Option 'MYSQLND_UH_MYSQLND_OPT_MAX_ALLOWED_PACKET' set to 3221225472proxy::setClientOption returns trueproxy::setClientOption(array (  0 => NULL,  1 => 211,  2 => 'mysql_native_password',))Option 'MYSQLND_UH_MYSQLND_OPT_AUTH_PROTOCOL' set to 'mysql_native_password'proxy::setClientOption returns trueproxy::setClientOption(array (  0 => NULL,  1 => 8,  2 => 1,))Option 'MYSQLND_UH_MYSQLND_OPT_LOCAL_INFILE' set to 1proxy::setClientOption returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_real_connect
mysqli_options
22.9.8.7.42. MysqlndUhConnection::setServerOption

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::setServerOption

    Sets a server option

Description

public void MysqlndUhConnection::setServerOption(mysqlnd_connection connection,
int option);

Sets a server option.

Parameters

connection

Mysqlnd connection handle. Do not modify!

option

The option to be set.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.364. MysqlndUhConnection::setServerOptionexample

<?phpfunction server_option_to_string($option) { $ret = 'unknown'; switch ($option) {  case MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_ON:   $ret = 'MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_ON';   break;  case MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_OFF:   $ret = 'MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_ON';   break; } return $ret;}class proxy extends MysqlndUhConnection { public function setServerOption($res, $option) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  printf("Option '%s' set\n", server_option_to_string($option));  $ret = parent::setServerOption($res, $option);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->multi_query("SELECT 1; SELECT 2");?> 

The above example will output:

proxy::setServerOption(array (  0 => NULL,  1 => 0,))Option 'MYSQLND_UH_SERVER_OPTION_MULTI_STATEMENTS_ON' setproxy::setServerOption returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_real_connect
mysqli_options
mysqli_multi_query
22.9.8.7.43. MysqlndUhConnection::shutdownServer

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::shutdownServer

    The shutdownServer purpose

Description

public void MysqlndUhConnection::shutdownServer(string MYSQLND_UH_RES_MYSQLND_NAME,
string "level");

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

MYSQLND_UH_RES_MYSQLND_NAME

"level"

Return Values

22.9.8.7.44. MysqlndUhConnection::simpleCommand

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::simpleCommand

    Sends a basic COM_* command

Description

public bool MysqlndUhConnection::simpleCommand(mysqlnd_connection connection,
int command,
string arg,
int ok_packet,
bool silent,
bool ignore_upsert_status);

Sends a basic COM_* command to MySQL.

Parameters

connection

Mysqlnd connection handle. Do not modify!

command

The COM command to be send.

arg

Optional COM command arguments.

ok_packet

The OK packet type.

silent

Whether mysqlnd may emit errors.

ignore_upsert_status

Whether to ignore UPDATE/INSERT status.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.365. MysqlndUhConnection::simpleCommandexample

<?phpfunction server_cmd_2_string($command) { $mapping = array(  MYSQLND_UH_MYSQLND_COM_SLEEP => "MYSQLND_UH_MYSQLND_COM_SLEEP",  MYSQLND_UH_MYSQLND_COM_QUIT => "MYSQLND_UH_MYSQLND_COM_QUIT",  MYSQLND_UH_MYSQLND_COM_INIT_DB => "MYSQLND_UH_MYSQLND_COM_INIT_DB",  MYSQLND_UH_MYSQLND_COM_QUERY => "MYSQLND_UH_MYSQLND_COM_QUERY",  MYSQLND_UH_MYSQLND_COM_FIELD_LIST => "MYSQLND_UH_MYSQLND_COM_FIELD_LIST",  MYSQLND_UH_MYSQLND_COM_CREATE_DB => "MYSQLND_UH_MYSQLND_COM_CREATE_DB",  MYSQLND_UH_MYSQLND_COM_DROP_DB => "MYSQLND_UH_MYSQLND_COM_DROP_DB",  MYSQLND_UH_MYSQLND_COM_REFRESH => "MYSQLND_UH_MYSQLND_COM_REFRESH",  MYSQLND_UH_MYSQLND_COM_SHUTDOWN => "MYSQLND_UH_MYSQLND_COM_SHUTDOWN",  MYSQLND_UH_MYSQLND_COM_STATISTICS => "MYSQLND_UH_MYSQLND_COM_STATISTICS",  MYSQLND_UH_MYSQLND_COM_PROCESS_INFO => "MYSQLND_UH_MYSQLND_COM_PROCESS_INFO",  MYSQLND_UH_MYSQLND_COM_CONNECT => "MYSQLND_UH_MYSQLND_COM_CONNECT",  MYSQLND_UH_MYSQLND_COM_PROCESS_KILL => "MYSQLND_UH_MYSQLND_COM_PROCESS_KILL",  MYSQLND_UH_MYSQLND_COM_DEBUG => "MYSQLND_UH_MYSQLND_COM_DEBUG",  MYSQLND_UH_MYSQLND_COM_PING => "MYSQLND_UH_MYSQLND_COM_PING",  MYSQLND_UH_MYSQLND_COM_TIME => "MYSQLND_UH_MYSQLND_COM_TIME",  MYSQLND_UH_MYSQLND_COM_DELAYED_INSERT => "MYSQLND_UH_MYSQLND_COM_DELAYED_INSERT",  MYSQLND_UH_MYSQLND_COM_CHANGE_USER => "MYSQLND_UH_MYSQLND_COM_CHANGE_USER",  MYSQLND_UH_MYSQLND_COM_BINLOG_DUMP => "MYSQLND_UH_MYSQLND_COM_BINLOG_DUMP",  MYSQLND_UH_MYSQLND_COM_TABLE_DUMP => "MYSQLND_UH_MYSQLND_COM_TABLE_DUMP",  MYSQLND_UH_MYSQLND_COM_CONNECT_OUT => "MYSQLND_UH_MYSQLND_COM_CONNECT_OUT",  MYSQLND_UH_MYSQLND_COM_REGISTER_SLAVED => "MYSQLND_UH_MYSQLND_COM_REGISTER_SLAVED",  MYSQLND_UH_MYSQLND_COM_STMT_PREPARE => "MYSQLND_UH_MYSQLND_COM_STMT_PREPARE",  MYSQLND_UH_MYSQLND_COM_STMT_EXECUTE => "MYSQLND_UH_MYSQLND_COM_STMT_EXECUTE",  MYSQLND_UH_MYSQLND_COM_STMT_SEND_LONG_DATA =>   "MYSQLND_UH_MYSQLND_COM_STMT_SEND_LONG_DATA",  MYSQLND_UH_MYSQLND_COM_STMT_CLOSE => "MYSQLND_UH_MYSQLND_COM_STMT_CLOSE",  MYSQLND_UH_MYSQLND_COM_STMT_RESET => "MYSQLND_UH_MYSQLND_COM_STMT_RESET",  MYSQLND_UH_MYSQLND_COM_SET_OPTION => "MYSQLND_UH_MYSQLND_COM_SET_OPTION",  MYSQLND_UH_MYSQLND_COM_STMT_FETCH => "MYSQLND_UH_MYSQLND_COM_STMT_FETCH",  MYSQLND_UH_MYSQLND_COM_DAEMON => "MYSQLND_UH_MYSQLND_COM_DAEMON",  MYSQLND_UH_MYSQLND_COM_END => "MYSQLND_UH_MYSQLND_COM_END", ); return (isset($mapping[$command])) ? $mapping[$command] : 'unknown';}function ok_packet_2_string($ok_packet) { $mapping = array(  MYSQLND_UH_MYSQLND_PROT_GREET_PACKET => "MYSQLND_UH_MYSQLND_PROT_GREET_PACKET",  MYSQLND_UH_MYSQLND_PROT_AUTH_PACKET => "MYSQLND_UH_MYSQLND_PROT_AUTH_PACKET",  MYSQLND_UH_MYSQLND_PROT_OK_PACKET => "MYSQLND_UH_MYSQLND_PROT_OK_PACKET",  MYSQLND_UH_MYSQLND_PROT_EOF_PACKET => "MYSQLND_UH_MYSQLND_PROT_EOF_PACKET",  MYSQLND_UH_MYSQLND_PROT_CMD_PACKET => "MYSQLND_UH_MYSQLND_PROT_CMD_PACKET",  MYSQLND_UH_MYSQLND_PROT_RSET_HEADER_PACKET =>   "MYSQLND_UH_MYSQLND_PROT_RSET_HEADER_PACKET",  MYSQLND_UH_MYSQLND_PROT_RSET_FLD_PACKET => "MYSQLND_UH_MYSQLND_PROT_RSET_FLD_PACKET",  MYSQLND_UH_MYSQLND_PROT_ROW_PACKET => "MYSQLND_UH_MYSQLND_PROT_ROW_PACKET",  MYSQLND_UH_MYSQLND_PROT_STATS_PACKET => "MYSQLND_UH_MYSQLND_PROT_STATS_PACKET",  MYSQLND_UH_MYSQLND_PREPARE_RESP_PACKET => "MYSQLND_UH_MYSQLND_PREPARE_RESP_PACKET",  MYSQLND_UH_MYSQLND_CHG_USER_RESP_PACKET => "MYSQLND_UH_MYSQLND_CHG_USER_RESP_PACKET",  MYSQLND_UH_MYSQLND_PROT_LAST => "MYSQLND_UH_MYSQLND_PROT_LAST", ); return (isset($mapping[$ok_packet])) ? $mapping[$ok_packet] : 'unknown';}class proxy extends MysqlndUhConnection { public function simpleCommand($conn, $command, $arg, $ok_packet, $silent,  $ignore_upsert_status) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  printf("Command '%s'\n", server_cmd_2_string($command));  printf("OK packet '%s'\n",  ok_packet_2_string($ok_packet));  $ret = parent::simpleCommand($conn, $command, $arg, $ok_packet, $silent,   $ignore_upsert_status);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("SELECT 1");?> 

The above example will output:

proxy::simpleCommand(array (  0 => NULL,  1 => 3,  2 => 'SELECT 1',  3 => 13,  4 => false,  5 => false,))Command 'MYSQLND_UH_MYSQLND_COM_QUERY'OK packet 'MYSQLND_UH_MYSQLND_PROT_LAST'proxy::simpleCommand returns true:)proxy::simpleCommand(array (  0 => NULL,  1 => 1,  2 => '',  3 => 13,  4 => true,  5 => true,))Command 'MYSQLND_UH_MYSQLND_COM_QUIT'OK packet 'MYSQLND_UH_MYSQLND_PROT_LAST'proxy::simpleCommand returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.45. MysqlndUhConnection::simpleCommandHandleResponse

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::simpleCommandHandleResponse

    Process a response for a basic COM_* command send to the client

Description

public bool MysqlndUhConnection::simpleCommandHandleResponse(mysqlnd_connection connection,
int ok_packet,
bool silent,
int command,
bool ignore_upsert_status);

Process a response for a basic COM_* command send to the client.

Parameters

connection

Mysqlnd connection handle. Do not modify!

ok_packet

The OK packet type.

silent

Whether mysqlnd may emit errors.

command

The COM command to process results from.

ignore_upsert_status

Whether to ignore UPDATE/INSERT status.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.366. MysqlndUhConnection::simpleCommandHandleResponseexample

<?phpfunction server_cmd_2_string($command) { $mapping = array(  MYSQLND_UH_MYSQLND_COM_SLEEP => "MYSQLND_UH_MYSQLND_COM_SLEEP",  MYSQLND_UH_MYSQLND_COM_QUIT => "MYSQLND_UH_MYSQLND_COM_QUIT",  MYSQLND_UH_MYSQLND_COM_INIT_DB => "MYSQLND_UH_MYSQLND_COM_INIT_DB",  MYSQLND_UH_MYSQLND_COM_QUERY => "MYSQLND_UH_MYSQLND_COM_QUERY",  MYSQLND_UH_MYSQLND_COM_FIELD_LIST => "MYSQLND_UH_MYSQLND_COM_FIELD_LIST",  MYSQLND_UH_MYSQLND_COM_CREATE_DB => "MYSQLND_UH_MYSQLND_COM_CREATE_DB",  MYSQLND_UH_MYSQLND_COM_DROP_DB => "MYSQLND_UH_MYSQLND_COM_DROP_DB",  MYSQLND_UH_MYSQLND_COM_REFRESH => "MYSQLND_UH_MYSQLND_COM_REFRESH",  MYSQLND_UH_MYSQLND_COM_SHUTDOWN => "MYSQLND_UH_MYSQLND_COM_SHUTDOWN",  MYSQLND_UH_MYSQLND_COM_STATISTICS => "MYSQLND_UH_MYSQLND_COM_STATISTICS",  MYSQLND_UH_MYSQLND_COM_PROCESS_INFO => "MYSQLND_UH_MYSQLND_COM_PROCESS_INFO",  MYSQLND_UH_MYSQLND_COM_CONNECT => "MYSQLND_UH_MYSQLND_COM_CONNECT",  MYSQLND_UH_MYSQLND_COM_PROCESS_KILL => "MYSQLND_UH_MYSQLND_COM_PROCESS_KILL",  MYSQLND_UH_MYSQLND_COM_DEBUG => "MYSQLND_UH_MYSQLND_COM_DEBUG",  MYSQLND_UH_MYSQLND_COM_PING => "MYSQLND_UH_MYSQLND_COM_PING",  MYSQLND_UH_MYSQLND_COM_TIME => "MYSQLND_UH_MYSQLND_COM_TIME",  MYSQLND_UH_MYSQLND_COM_DELAYED_INSERT => "MYSQLND_UH_MYSQLND_COM_DELAYED_INSERT",  MYSQLND_UH_MYSQLND_COM_CHANGE_USER => "MYSQLND_UH_MYSQLND_COM_CHANGE_USER",  MYSQLND_UH_MYSQLND_COM_BINLOG_DUMP => "MYSQLND_UH_MYSQLND_COM_BINLOG_DUMP",  MYSQLND_UH_MYSQLND_COM_TABLE_DUMP => "MYSQLND_UH_MYSQLND_COM_TABLE_DUMP",  MYSQLND_UH_MYSQLND_COM_CONNECT_OUT => "MYSQLND_UH_MYSQLND_COM_CONNECT_OUT",  MYSQLND_UH_MYSQLND_COM_REGISTER_SLAVED => "MYSQLND_UH_MYSQLND_COM_REGISTER_SLAVED",  MYSQLND_UH_MYSQLND_COM_STMT_PREPARE => "MYSQLND_UH_MYSQLND_COM_STMT_PREPARE",  MYSQLND_UH_MYSQLND_COM_STMT_EXECUTE => "MYSQLND_UH_MYSQLND_COM_STMT_EXECUTE",  MYSQLND_UH_MYSQLND_COM_STMT_SEND_LONG_DATA =>   "MYSQLND_UH_MYSQLND_COM_STMT_SEND_LONG_DATA",  MYSQLND_UH_MYSQLND_COM_STMT_CLOSE => "MYSQLND_UH_MYSQLND_COM_STMT_CLOSE",  MYSQLND_UH_MYSQLND_COM_STMT_RESET => "MYSQLND_UH_MYSQLND_COM_STMT_RESET",  MYSQLND_UH_MYSQLND_COM_SET_OPTION => "MYSQLND_UH_MYSQLND_COM_SET_OPTION",  MYSQLND_UH_MYSQLND_COM_STMT_FETCH => "MYSQLND_UH_MYSQLND_COM_STMT_FETCH",  MYSQLND_UH_MYSQLND_COM_DAEMON => "MYSQLND_UH_MYSQLND_COM_DAEMON",  MYSQLND_UH_MYSQLND_COM_END => "MYSQLND_UH_MYSQLND_COM_END", ); return (isset($mapping[$command])) ? $mapping[$command] : 'unknown';}function ok_packet_2_string($ok_packet) { $mapping = array(  MYSQLND_UH_MYSQLND_PROT_GREET_PACKET => "MYSQLND_UH_MYSQLND_PROT_GREET_PACKET",  MYSQLND_UH_MYSQLND_PROT_AUTH_PACKET => "MYSQLND_UH_MYSQLND_PROT_AUTH_PACKET",  MYSQLND_UH_MYSQLND_PROT_OK_PACKET => "MYSQLND_UH_MYSQLND_PROT_OK_PACKET",  MYSQLND_UH_MYSQLND_PROT_EOF_PACKET => "MYSQLND_UH_MYSQLND_PROT_EOF_PACKET",  MYSQLND_UH_MYSQLND_PROT_CMD_PACKET => "MYSQLND_UH_MYSQLND_PROT_CMD_PACKET",  MYSQLND_UH_MYSQLND_PROT_RSET_HEADER_PACKET =>   "MYSQLND_UH_MYSQLND_PROT_RSET_HEADER_PACKET",  MYSQLND_UH_MYSQLND_PROT_RSET_FLD_PACKET => "MYSQLND_UH_MYSQLND_PROT_RSET_FLD_PACKET",  MYSQLND_UH_MYSQLND_PROT_ROW_PACKET => "MYSQLND_UH_MYSQLND_PROT_ROW_PACKET",  MYSQLND_UH_MYSQLND_PROT_STATS_PACKET => "MYSQLND_UH_MYSQLND_PROT_STATS_PACKET",  MYSQLND_UH_MYSQLND_PREPARE_RESP_PACKET => "MYSQLND_UH_MYSQLND_PREPARE_RESP_PACKET",  MYSQLND_UH_MYSQLND_CHG_USER_RESP_PACKET => "MYSQLND_UH_MYSQLND_CHG_USER_RESP_PACKET",  MYSQLND_UH_MYSQLND_PROT_LAST => "MYSQLND_UH_MYSQLND_PROT_LAST", ); return (isset($mapping[$ok_packet])) ? $mapping[$ok_packet] : 'unknown';}class proxy extends MysqlndUhConnection { public function simpleCommandHandleResponse($conn, $ok_packet, $silent, $command,  $ignore_upsert_status) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  printf("Command '%s'\n", server_cmd_2_string($command));  printf("OK packet '%s'\n",  ok_packet_2_string($ok_packet));  $ret = parent::simpleCommandHandleResponse($conn, $ok_packet, $silent, $command,   $ignore_upsert_status);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysql = mysql_connect("localhost", "root", "");mysql_query("SELECT 1 FROM DUAL", $mysql);?> 

The above example will output:

proxy::simpleCommandHandleResponse(array (  0 => NULL,  1 => 5,  2 => false,  3 => 27,  4 => true,))Command 'MYSQLND_UH_MYSQLND_COM_SET_OPTION'OK packet 'MYSQLND_UH_MYSQLND_PROT_EOF_PACKET'proxy::simpleCommandHandleResponse returns true

See Also

mysqlnd_uh_set_connection_proxy
22.9.8.7.46. MysqlndUhConnection::sslSet

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::sslSet

    Used for establishing secure connections using SSL

Description

public bool MysqlndUhConnection::sslSet(mysqlnd_connection connection,
string key,
string cert,
string ca,
string capath,
string cipher);

Used for establishing secure connections using SSL.

Parameters

connection

Mysqlnd connection handle. Do not modify!

key

The path name to the key file.

cert

The path name to the certificate file.

ca

The path name to the certificate authority file.

capath

The pathname to a directory that contains trusted SSL CA certificates in PEM format.

cipher

A list of allowable ciphers to use for SSL encryption.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.367. MysqlndUhConnection::sslSetexample

<?phpclass proxy extends MysqlndUhConnection { public function sslSet($conn, $key, $cert, $ca, $capath, $cipher) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::sslSet($conn, $key, $cert, $ca, $capath, $cipher);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->ssl_set("key", "cert", "ca", "capath", "cipher");?> 

The above example will output:

proxy::sslSet(array (  0 => NULL,  1 => 'key',  2 => 'cert',  3 => 'ca',  4 => 'capath',  5 => 'cipher',))proxy::sslSet returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_ssl_set
22.9.8.7.47. MysqlndUhConnection::stmtInit

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::stmtInit

    Initializes a statement and returns a resource for use with mysqli_statement::prepare

Description

public resource MysqlndUhConnection::stmtInit(mysqlnd_connection connection);

Initializes a statement and returns a resource for use with mysqli_statement::prepare.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Resource of type Mysqlnd Prepared Statement (internal only - you must not modify it!). The documentation may also refer to such resources using the alias name mysqlnd_prepared_statement.

Examples

Example 22.368. MysqlndUhConnection::stmtInitexample

<?phpclass proxy extends MysqlndUhConnection { public function stmtInit($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  var_dump($res);  $ret = parent::stmtInit($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  var_dump($ret);  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$stmt = $mysqli->prepare("SELECT 1 AS _one FROM DUAL");$stmt->execute();$one = NULL;$stmt->bind_result($one);$stmt->fetch();var_dump($one);?> 

The above example will output:

proxy::stmtInit(array (  0 => NULL,))resource(19) of type (Mysqlnd Connection)proxy::stmtInit returns NULLresource(246) of type (Mysqlnd Prepared Statement (internal only - you must not modify it!))int(1)

See Also

mysqlnd_uh_set_connection_proxy
mysqli_stmt_init
22.9.8.7.48. MysqlndUhConnection::storeResult

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::storeResult

    Transfers a result set from the last query

Description

public resource MysqlndUhConnection::storeResult(mysqlnd_connection connection);

Transfers a result set from the last query.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Resource of type Mysqlnd Resultset (internal only - you must not modify it!). The documentation may also refer to such resources using the alias name mysqlnd_resultset.

Examples

Example 22.369. MysqlndUhConnection::storeResultexample

<?phpclass proxy extends MysqlndUhConnection { public function storeResult($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::storeResult($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  var_dump($ret);  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$res = $mysqli->query("SELECT 'Also called buffered result' AS _msg FROM DUAL");var_dump($res->fetch_assoc());$mysqli->real_query("SELECT 'Good morning!' AS _msg FROM DUAL");$res = $mysqli->store_result();var_dump($res->fetch_assoc());?> 

The above example will output:

proxy::storeResult(array (  0 => NULL,))proxy::storeResult returns NULLresource(475) of type (Mysqlnd Resultset (internal only - you must not modify it!))array(1) {  ["_msg"]=>  string(27) "Also called buffered result"}proxy::storeResult(array (  0 => NULL,))proxy::storeResult returns NULLresource(730) of type (Mysqlnd Resultset (internal only - you must not modify it!))array(1) {  ["_msg"]=>  string(13) "Good morning!"}

See Also

mysqlnd_uh_set_connection_proxy
mysqli_store_result
mysqli_real_query
22.9.8.7.49. MysqlndUhConnection::txCommit

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::txCommit

    Commits the current transaction

Description

public bool MysqlndUhConnection::txCommit(mysqlnd_connection connection);

Commits the current transaction.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.370. MysqlndUhConnection::txCommitexample

<?phpclass proxy extends MysqlndUhConnection { public function txCommit($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::txCommit($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->commit();?> 

The above example will output:

proxy::txCommit(array (  0 => NULL,))proxy::txCommit returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_commit
22.9.8.7.50. MysqlndUhConnection::txRollback

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::txRollback

    Rolls back current transaction

Description

public bool MysqlndUhConnection::txRollback(mysqlnd_connection connection);

Rolls back current transaction.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.371. MysqlndUhConnection::txRollbackexample

<?phpclass proxy extends MysqlndUhConnection { public function txRollback($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::txRollback($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->rollback();?> 

The above example will output:

proxy::txRollback(array (  0 => NULL,))proxy::txRollback returns true

See Also

mysqlnd_uh_set_connection_proxy
mysqli_commit
22.9.8.7.51. MysqlndUhConnection::useResult

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhConnection::useResult

    Initiate a result set retrieval

Description

public resource MysqlndUhConnection::useResult(mysqlnd_connection connection);

Initiate a result set retrieval.

Parameters

connection

Mysqlnd connection handle. Do not modify!

Return Values

Resource of type Mysqlnd Resultset (internal only - you must not modify it!). The documentation may also refer to such resources using the alias name mysqlnd_resultset.

Examples

Example 22.372. MysqlndUhConnection::useResultexample

<?phpclass proxy extends MysqlndUhConnection { public function useResult($res) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $ret = parent::useResult($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  var_dump($ret);  return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->real_query("SELECT 'Good morning!' AS _msg FROM DUAL");$res = $mysqli->use_result();var_dump($res->fetch_assoc());?> 

The above example will output:

proxy::useResult(array (  0 => NULL,))proxy::useResult returns NULLresource(425) of type (Mysqlnd Resultset (internal only - you must not modify it!))array(1) {  ["_msg"]=>  string(13) "Good morning!"}

See Also

mysqlnd_uh_set_connection_proxy
mysqli_use_result
mysqli_real_query

22.9.8.8. The MysqlndUhPreparedStatement class(MysqlndUhPreparedStatement)

Copyright 1997-2012 the PHP Documentation Group.

 MysqlndUhPreparedStatement {
MysqlndUhPreparedStatementMethods public MysqlndUhPreparedStatement::__construct();
public bool MysqlndUhPreparedStatement::execute(mysqlnd_prepared_statement statement);
public bool MysqlndUhPreparedStatement::prepare(mysqlnd_prepared_statement statement,
string query);
}
22.9.8.8.1. MysqlndUhPreparedStatement::__construct

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhPreparedStatement::__construct

    The __construct purpose

Description

public MysqlndUhPreparedStatement::__construct();

Warning

This function iscurrently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

22.9.8.8.2. MysqlndUhPreparedStatement::execute

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhPreparedStatement::execute

    Executes a prepared Query

Description

public bool MysqlndUhPreparedStatement::execute(mysqlnd_prepared_statement statement);

Executes a prepared Query.

Parameters

statement

Mysqlnd prepared statement handle. Do not modify! Resource of type Mysqlnd Prepared Statement (internal only - you must not modify it!).

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.373. MysqlndUhPreparedStatement::executeexample

<?phpclass stmt_proxy extends MysqlndUhPreparedStatement { public function execute($res) {  printf("%s(", __METHOD__);  var_dump($res);  printf(")\n");  $ret = parent::execute($res);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  var_dump($ret);  return $ret; }}mysqlnd_uh_set_statement_proxy(new stmt_proxy());$mysqli = new mysqli("localhost", "root", "", "test");$stmt = $mysqli->prepare("SELECT 'Labskaus' AS _msg FROM DUAL");$stmt->execute();$msg = NULL;$stmt->bind_result($msg);$stmt->fetch();var_dump($msg);?> 

The above example will output:

stmt_proxy::execute(resource(256) of type (Mysqlnd Prepared Statement (internal only - you must not modify it!)))stmt_proxy::execute returns truebool(true)string(8) "Labskaus"

See Also

mysqlnd_uh_set_statement_proxy
mysqli_stmt_execute
22.9.8.8.3. MysqlndUhPreparedStatement::prepare

Copyright 1997-2012 the PHP Documentation Group.

  • MysqlndUhPreparedStatement::prepare

    Prepare an SQL statement for execution

Description

public bool MysqlndUhPreparedStatement::prepare(mysqlnd_prepared_statement statement,
string query);

Prepare an SQL statement for execution.

Parameters

statement

Mysqlnd prepared statement handle. Do not modify! Resource of type Mysqlnd Prepared Statement (internal only - you must not modify it!).

query

The query to be prepared.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.374. MysqlndUhPreparedStatement::prepareexample

<?phpclass stmt_proxy extends MysqlndUhPreparedStatement { public function prepare($res, $query) {  printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));  $query = "SELECT 'No more you-know-what-I-mean for lunch, please' AS _msg FROM DUAL";  $ret = parent::prepare($res, $query);  printf("%s returns %s\n", __METHOD__, var_export($ret, true));  var_dump($ret);  return $ret; }}mysqlnd_uh_set_statement_proxy(new stmt_proxy());$mysqli = new mysqli("localhost", "root", "", "test");$stmt = $mysqli->prepare("SELECT 'Labskaus' AS _msg FROM DUAL");$stmt->execute();$msg = NULL;$stmt->bind_result($msg);$stmt->fetch();var_dump($msg);?> 

The above example will output:

stmt_proxy::prepare(array (  0 => NULL,  1 => 'SELECT \'Labskaus\' AS _msg FROM DUAL',))stmt_proxy::prepare returns truebool(true)string(46) "No more you-know-what-I-mean for lunch, please"

See Also

mysqlnd_uh_set_statement_proxy
mysqli_stmt_prepare
mysqli_prepare

22.9.8.9. Mysqlnd_uh Functions

Copyright 1997-2012 the PHP Documentation Group.

22.9.8.9.1. mysqlnd_uh_convert_to_mysqlnd

Copyright 1997-2012 the PHP Documentation Group.

  • mysqlnd_uh_convert_to_mysqlnd

    Converts a MySQL connection handle into a mysqlnd connection handle

Description

resource mysqlnd_uh_convert_to_mysqlnd(mysqli mysql_connection);

Converts a MySQL connection handle into a mysqlnd connection handle. After conversion you can execute mysqlnd library calls on the connection handle. This can be used to access mysqlnd functionality not made available through user space API calls.

The function can be disabled with mysqlnd_uh.enable. If mysqlnd_uh.enable is set to FALSE the function will not install the proxy and always return TRUE . Additionally, an error of the type E_WARNING may be emitted. The error message may read like PHP Warning: mysqlnd_uh_convert_to_mysqlnd(): (Mysqlnd User Handler) The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enable = false. You are not allowed to call this function [...].

Parameters

MySQL connection handle

A MySQL connection handle of type mysql, mysqli or PDO_MySQL.

Return Values

A mysqlnd connection handle.

Changelog

VersionDescription
5.4.0The mysql_connection parameter can now be of type mysql, PDO_MySQL, or mysqli. Before, only themysqli type was allowed.

Examples

Example 22.375. mysqlnd_uh_convert_to_mysqlndexample

<?php/* PDO user API gives no access to connection thread id */$mysql_connection = new PDO("mysql:host=localhost;dbname=test", "root", "");/* Convert PDO MySQL handle to mysqlnd handle */$mysqlnd = mysqlnd_uh_convert_to_mysqlnd($mysql_connection);/* Create Proxy to call mysqlnd connection class methods */$obj = new MySQLndUHConnection();/* Call mysqlnd_conn::get_thread_id */var_dump($obj->getThreadId($mysqlnd));/* Use SQL to fetch connection thread id */var_dump($mysql_connection->query("SELECT CONNECTION_ID()")->fetchAll());?> 

The above example will output:

int(27054)array(1) {  [0]=>  array(2) { ["CONNECTION_ID()"]=> string(5) "27054" [0]=> string(5) "27054"  }}

See Also

mysqlnd_uh.enable
22.9.8.9.2. mysqlnd_uh_set_connection_proxy

Copyright 1997-2012 the PHP Documentation Group.

  • mysqlnd_uh_set_connection_proxy

    Installs a proxy for mysqlnd connections

Description

bool mysqlnd_uh_set_connection_proxy(MysqlndUhConnection connection_proxy,
mysqli mysqli_connection);

Installs a proxy object to hook mysqlnd's connection objects methods. Once installed, the proxy will be used for all MySQL connections opened with mysqli, mysql or PDO_MYSQL, assuming that the listed extensions are compiled to use the mysqlnd library.

The function can be disabled with mysqlnd_uh.enable. If mysqlnd_uh.enable is set to FALSE the function will not install the proxy and always return TRUE . Additionally, an error of the type E_WARNING may be emitted. The error message may read like PHP Warning: mysqlnd_uh_set_connection_proxy(): (Mysqlnd User Handler) The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enable = false. The proxy has not been installed [...].

Parameters

connection_proxy

A proxy object of type MysqlndUhConnection.

mysqli_connection

Object of type mysqli. If given, the proxy will be set for this particular connection only.

Return Values

Returns TRUE on success. Otherwise, returns FALSE

Examples

Example 22.376. mysqlnd_uh_set_connection_proxyexample

<?php$mysqli = new mysqli("localhost", "root", "", "test");$mysqli->query("SELECT 'No proxy installed, yet'");class proxy extends MysqlndUhConnection { public function query($res, $query) {   printf("%s(%s)\n", __METHOD__, var_export(func_get_args(), true));   $ret = parent::query($res, $query);   printf("%s returns %s\n", __METHOD__, var_export($ret, true));   return $ret; }}mysqlnd_uh_set_connection_proxy(new proxy());$mysqli->query("SELECT 'mysqlnd rocks!'");$mysql = mysql_connect("localhost", "root", "", "test");mysql_query("SELECT 'Ahoy Andrey!'", $mysql);$pdo = new PDO("mysql:host=localhost;dbname=test", "root", "");$pdo->query("SELECT 'Moin Johannes!'");?> 

The above example will output:

proxy::query(array (  0 => NULL,  1 => 'SELECT \'mysqlnd rocks!\'',))proxy::query returns trueproxy::query(array (  0 => NULL,  1 => 'SELECT \'Ahoy Andrey!\'',))proxy::query returns trueproxy::query(array (  0 => NULL,  1 => 'SELECT \'Moin Johannes!\'',))proxy::query returns true

See Also

mysqlnd_uh_set_statement_proxy
mysqlnd_uh.enable
22.9.8.9.3. mysqlnd_uh_set_statement_proxy

Copyright 1997-2012 the PHP Documentation Group.

  • mysqlnd_uh_set_statement_proxy

    Installs a proxy for mysqlnd statements

Description

bool mysqlnd_uh_set_statement_proxy(MysqlndUhStatement statement_proxy);

Installs a proxy for mysqlnd statements. The proxy object will be used for all mysqlnd prepared statement objects, regardless which PHP MySQL extension (mysqli, mysql, PDO_MYSQL) has created them as long as the extension is compiled to use the mysqlnd library.

The function can be disabled with mysqlnd_uh.enable. If mysqlnd_uh.enable is set to FALSE the function will not install the proxy and always return TRUE . Additionally, an error of the type E_WARNING may be emitted. The error message may read like PHP Warning: mysqlnd_uh_set_statement_proxy(): (Mysqlnd User Handler) The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enable = false. The proxy has not been installed [...].

Parameters

statement_proxy

The mysqlnd statement proxy object of type MysqlndUhStatement

Return Values

Returns TRUE on success. Otherwise, returns FALSE

See Also

mysqlnd_uh_set_connection_proxy
mysqlnd_uh.enable

22.9.8.10. Change History

Copyright 1997-2012 the PHP Documentation Group.

The Change History lists major changes users need to be aware if upgrading from one version to another. It is a high level summary of selected changes that may impact applications or might even break backwards compatibility. See also the CHANGES file contained in the source for additional changelog information. The commit history is also available.

22.9.8.10.1. PECL/mysqlnd_uh 1.0 series

Copyright 1997-2012 the PHP Documentation Group.

1.0.1-alpha

  • Release date: TBD
  • Motto/theme: bug fix release

Feature changes

  • Support of PHP 5.4.0 or later.
  • BC break: MysqlndUhConnection::changeUser requires additional passwd_len parameter.
  • BC break: MYSQLND_UH_VERSION_STR renamed to MYSQLND_UH_VERSION. MYSQLND_UH_VERSION renamed to MYSQLND_UH_VERSION_ID.
  • BC break: mysqlnd_uh.enabled configuration setting renamed to mysqlnd_uh.enable.

1.0.0-alpha

  • Release date: 08/2010
  • Motto/theme: Initial release

22.9.9. Mysqlnd connection multiplexing plugin (mysqlnd_mux)

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd multiplexing plugin (mysqlnd_mux) multiplexes MySQL connections established by all PHP MySQL extensions that use the MySQL native driver (mysqlnd) for PHP.

The MySQL native driver for PHP features an internal C API for plugins, such as the connection multiplexing plugin, which can extend the functionality of mysqlnd. See the mysqlnd for additional details about its benefits over the MySQL Client Library libmysql/libmysqlclient.

Mysqlnd plugins like mysqlnd_mux operate, for the most part, transparently from a user perspective. The connection multiplexing plugin supports all PHP applications, and all MySQL PHP extensions. It does not change existing APIs. Therefore, it can easily be used with existing PHP applications.

Note

This is a proof-of-concept. All features are at an early stage. Not all kinds of queries are handled by the plugin yet. Thus, it cannot be used in a drop-in fashion at the moment.

Please, do not use this version in production environments.

22.9.9.1. Key Features

Copyright 1997-2012 the PHP Documentation Group.

The key features of mysqlnd_mux are as follows:

  • Transparent and therefore easy to use:

    • Supports all of the PHP MySQL extensions.

    • Little to no application changes are required, dependent on the required usage scenario.

  • Reduces server load and connection establishment latency:

    • Opens less connections to the MySQL server.

    • Less connections to MySQL mean less work for the MySQL server. In a client-server environment scaling the server is often more difficult than scaling the client. Multiplexing helps with horizontal scale-out (scale-by-client).

    • Pooling saves connection time.

    • Multiplexed connection: multiple user handles share the same network connection. Once opened, a network connection is cached and shared among multiple user handles. There is a 1:n relationship between internal network connection and user connection handles.

    • Persistent connection: a network connection is kept open at the end of the web request, if the PHP deployment model allows. Thus, subsequently web requests can reuse a previously opened connection. Like other resources, network connections are bound to the scope of a process. Thus, they can be reused for all web requests served by a process.

22.9.9.2. Limitations

Copyright 1997-2012 the PHP Documentation Group.

The proof-of-concept does not support unbuffered queries, prepared statements, and asynchronous queries.

The connection pool is using a combination of the transport method and hostname as keys. As a consequence, two connections to the same host using the same transport method (TCP/IP, Unix socket, Windows named pipe) will be linked to the same pooled connection even if username and password differ. Be aware of the possible security implications.

The proof-of-concept is transaction agnostic. It does not about SQL transactions.

Note

Applications must be aware of the consequences of connection sharing connections.

22.9.9.3. About the name mysqlnd_mux

Copyright 1997-2012 the PHP Documentation Group.

The shortcut mysqlnd_mux stands for mysqlnd connection multiplexing plugin.

22.9.9.4. Concepts

Copyright 1997-2012 the PHP Documentation Group.

This explains the architecture and related concepts for this plugin. Reading and understanding these concepts is required to successfully use this plugin.

22.9.9.4.1. Architecture

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd connection multiplexing plugin is implemented as a PHP extension. It is written in C and operates under the hood of PHP. During the startup of the PHP interpreter, in the module initialization phase of the PHP engine, it gets registered as a mysqlnd plugin to replace specific mysqlnd C methods.

The mysqlnd library uses PHP streams to communicate with the MySQL server. PHP streams are accessed by the mysqlnd library through its net module. The mysqlnd connection multiplexing plugin proxies methods of the mysqlnd library net module to control opening and closing of network streams.

Upon opening a user connection to MySQL using the appropriate connection functions of either mysqli, PDO_MYSQL or ext/mysql, the plugin will search its connection pool for an open network connection. If the pool contains a network connection to the host specified by the connect function using the transport method requested (TCP/IP, Unix domain socket, Windows named pipe), the pooled connection is linked to the user handle. Otherwise, a new network connection is opened, put into the poolm and associated with the user connection handle. This way, multiple user handles can be linked to the same network connection.

22.9.9.4.2. Connection pool

Copyright 1997-2012 the PHP Documentation Group.

The plugins connection pool is created when PHP initializes its modules (MINIT) and free'd when PHP shuts down the modules (MSHUTDOWN). This is the same as for persistent MySQL connections.

Depending on the deployment model, the pool is used for the duration of one or multiple web requests. Network connections are bound to the lifespan of an operating system level process. If the PHP process serves multiple web requests as it is the case for Fast-CGI or threaded web server deployments, then the pooled connections can be reused over multiple connections. Because multiplexing means sharing connections, it can even happen with a threaded deployment that two threads or two distinct web requests are linked to one pooled network connections.

A pooled connection is explicitly closed once the last reference to it is released. An implicit close happens when PHP shuts down its modules.

22.9.9.4.3. Sharing connections

Copyright 1997-2012 the PHP Documentation Group.

The PHP mysqlnd connection multiplexing plugin changes the relationship between a users connection handle and the underlying MySQL connection. Without the plugin, every MySQL connection belongs to exactly one user connection at a time. The multiplexing plugin changes. A MySQL connection is shared among multiple user handles. There no one-to-one relation if using the plugin.

Sharing pooled connections has an impact on the connection state. State changing operations from multiple user handles pointing to one MySQL connection are not isolated from each other. If, for example, a session variable is set through one user connection handle, the session variable becomes visible to all other user handles that reference the same underlying MySQL connection.

This is similar in concept to connection state related phenomens described for the PHP mysqlnd replication and load balancing plugin. Please, check the PECL/mysqlnd_ms documentation for more details on the state of a connection.

The proof-of-concept takes no measures to isolate multiplexed connections from each other.

22.9.9.5. Installing/Configuring

Copyright 1997-2012 the PHP Documentation Group.

22.9.9.5.1. Requirements

Copyright 1997-2012 the PHP Documentation Group.

PHP 5.5.0 or newer. Some advanced functionality requires PHP 5.5.0 or newer.

The mysqlnd_mux replication and load balancing plugin supports all PHP applications and all available PHP MySQL extensions (mysqli, mysql, PDO_MYSQL). The PHP MySQL extension must be configured to use mysqlnd in order to be able to use the mysqlnd_mux plugin for mysqlnd.

22.9.9.5.2. Installation

Copyright 1997-2012 the PHP Documentation Group.

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/mysqlnd_mux

22.9.9.5.3. Runtime Configuration

Copyright 1997-2012 the PHP Documentation Group.

The behaviour of these functions is affected by settings in php.ini.

Table 22.75. Mysqlnd_mux Configure Options

NameDefaultChangeableChangelog
mysqlnd_mux.enable0PHP_INI_SYSTEM 

Here's a short explanation of the configuration directives.

mysqlnd_mux.enable integer

Enables or disables the plugin. If disabled, the extension will not plug into mysqlnd to proxy internal mysqlnd C API calls.

22.9.9.6. Predefined Constants

Copyright 1997-2012 the PHP Documentation Group.

The constants below are defined by this extension, andwill only be available when the extension has eitherbeen compiled into PHP or dynamically loaded at runtime.

Other

The plugins version number can be obtained using MYSQLND_MUX_VERSION or MYSQLND_MUX_VERSION_ID . MYSQLND_MUX_VERSION is the string representation of the numerical version number MYSQLND_MUX_VERSION_ID , which is an integer such as 10000. Developers can calculate the version number as follows.

Version (part)Example
Major*100001*10000 = 10000
Minor*1000*100 = 0
Patch0 = 0
MYSQLND_MUX_VERSION_ID10000

MYSQLND_MUX_VERSION (string)
Plugin version string, for example, "1.0.0-prototype".
MYSQLND_MUX_VERSION_ID (integer)
Plugin version number, for example, 10000.

22.9.9.7. Change History

Copyright 1997-2012 the PHP Documentation Group.

This change history is a high level summary of selected changes that may impact applications and/or break backwards compatibility.

See also the CHANGES file in the source distribution for a complete list of changes.

22.9.9.7.1. PECL/mysqlnd_mux 1.0 series

Copyright 1997-2012 the PHP Documentation Group.

1.0.0-pre-alpha

  • Release date: no package released, initial check-in 09/2012
  • Motto/theme: Proof of concept

Initial check-in. Essentially a demo of the mysqlnd plugin API.

Note

This is the current development series. All features are at an early stage. Changes may happen at any time without prior notice. Please, do not use this version in production environments.

The documentation may not reflect all changes yet.

22.9.10. Mysqlnd Memache plugin (mysqlnd_memcache)

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd memcache plugin (mysqlnd_memcache) is an PHP extension for transparently translating SQL into requests for the MySQL InnoDB Memcached Daemon Plugin (server plugin). It includes experimental support for the MySQL Cluster Memcached Daemon. The server plugin provides access to data stored inside MySQL InnoDB (respectively MySQL Cluster NDB) tables using the Memcache protocol. This PHP extension, which supports all PHP MySQL extensions that use mysqlnd, will identify tables exported in this way and will translate specific SELECT queries into Memcache requests.

Figure 22.92. mysqlnd_memcache data flow

mysqlnd_memcache data flow

Note

This plugin depends on the MySQL InnoDB Memcached Daemon Plugin. It is not provided to be used with a stand-alone Memcached. For a generic query cache using Memcached look at the mysqlnd query cache plugin. For direct Memcache access look at the memcache and memcached extensions.

The MySQL native driver for PHP is a C library that ships together with PHP as of PHP 5.3.0. It serves as a drop-in replacement for the MySQL Client Library (libmysql/libmysqlclient). Using mysqlnd has several advantages: no extra downloads are required because it's bundled with PHP, it's under the PHP license, there is lower memory consumption in certain cases, and it contains new functionality such as asynchronous queries.

The mysqlnd_mmemcache operates, for the most part, transparently from a user perspective. The mysqlnd memcache plugin supports all PHP applications, and all MySQL PHP extensions. It does not change existing APIs. Therefore, it can easily be used with existing PHP applications.

The MySQL Memcache plugins add key-value style access method for data stored in InnoDB resp. NDB (MySQL Cluster) SQL tables through the Memcache protocol. This type of key-value access if often faster than using SQL.

22.9.10.1. Key Features

Copyright 1997-2012 the PHP Documentation Group.

The key features of PECL/mysqlnd_memcache are as follows.

  • Possible performance benefits

    • Client-side: light-weight protocol.

    • Server-side: no SQL parsing, direct access to the storage.

    • Please, run your own benchmarks! Actual performance results are highly dependent on setup and hardware used.

22.9.10.2. Limitations

Copyright 1997-2012 the PHP Documentation Group.

The initial version is not binary safe. Due to the way the MySQL Memcache plugins works there are restrictions related to separators.

Prepared statements and asynchronous queries are not supported. Result set meta data support is limited.

The mapping information for tables accessible via Memcache is not cached in the plugin between requests but fetched from the MySQL server each time a MySQL connection is associated with a Memcache connection. See mysqlnd_memcache_set for details.

22.9.10.3. On the name

Copyright 1997-2012 the PHP Documentation Group.

The shortcut mysqlnd_memcache stands for mysqlnd memcache plugin. Memcache refers to support of the MySQL Memcache plugins for InnoDB and NDB (MySQL Cluster). The plugin is not related to the Memcached cache server.

22.9.10.4. Quickstart and Examples

Copyright 1997-2012 the PHP Documentation Group.

The mysqlnd memcache plugin is easy to use. This quickstart will demo typical use-cases, and provide practical advice on getting started.

It is strongly recommended to read the reference sections in addition to the quickstart. The quickstart tries to avoid discussing theoretical concepts and limitations. Instead, it will link to the reference sections. It is safe to begin with the quickstart. However, before using the plugin in mission critical environments we urge you to read additionally the background information from the reference sections.

22.9.10.4.1. Setup

Copyright 1997-2012 the PHP Documentation Group.

The plugin is implemented as a PHP extension. See also the installation instructions to install this extension.

Compile or configure the PHP MySQL extension (API) (mysqli, PDO_MYSQL, mysql). That extension must use the mysqlnd library as because mysqlnd_memcache is a plugin for the mysqlnd library. For additional information, refer to the mysqlnd_memcache installation instructions.

Then, load this extension into PHP and activate the plugin in the PHP configuration file using the PHP configuration directive named mysqlnd_memcache.enable.

Example 22.377. Enabling the plugin (php.ini)

; On Windows the filename is php_mysqnd_memcache.dll; Load the extensionextension=mysqlnd_memcache.so; Enable itmysqlnd_memcache.enable=1

Follow the instructions given in the MySQL Reference Manual on installing the Memcache plugins for the MySQL server. Activate the plugins and configure Memcache access for SQL tables.

The examples in this quickguide assume that the following table exists, and that Memcache is configured with access to it.

Example 22.378. SQL table used for the Quickstart

CREATE TABLE test(  id CHAR(16),  f1 VARCHAR(255),  f2 VARCHAR(255),  f3 VARCHAR(255),  flags INT NOT NULL,  cas_column INT,  expire_time_column INT,  PRIMARY KEY(id)  ) ENGINE=InnoDB;INSERT INTO test (id, f1, f2, f3) VALUES (1, 'Hello', 'World', '!');INSERT INTO test (id, f1, f2, f3) VALUES (2, 'Lady', 'and', 'the tramp');INSERT INTO innodb_memcache.containers(  name, db_schema, db_table, key_columns, value_columns,   flags, cas_column, expire_time_column, unique_idx_name_on_key)VALUES (  'plugin_test', 'test', 'test', 'id', 'f1,f2,f3',  'flags', 'cas_column', 'expire_time_column', 'PRIMARY KEY');
22.9.10.4.2. Usage

Copyright 1997-2012 the PHP Documentation Group.

After associating a MySQL connection with a Memcache connection using mysqnd_memcache_set the plugin attempts to transparently replace SQL SELECT statements by a memcache access. For that purpose the plugin monitors all SQL statements executed and tries to match the statement string against MYSQLND_MEMCACHE_DEFAULT_REGEXP . In case of a match, the mysqlnd memcache plugin checks whether the SELECT is accessing only columns of a mapped table and the WHERE clause is limited to a single key lookup.

In case of the example SQL table, the plugin will use the Memcache interface of the MySQL server to fetch results for a SQL query like SELECT f1, f2, f3 WHERE id = n.

Example 22.379. Basic example.

<?php$mysqli = new mysqli("host", "user", "passwd", "database");$memc = new Memcached();$memc->addServer("host", 11211);mysqlnd_memcache_set($mysqli, $memc);/*   This is a query which queries table test using id as key in the WHERE part   and is accessing fields f1, f2 and f3. Therefore, mysqlnd_memcache   will intercept it and route it via memcache.*/$result = $mysqli->query("SELECT f1, f2, f3 FROM test WHERE id = 1");while ($row = $result->fetch_row()) { print_r($row);}/*   This is a query which queries table test but using f1 in the WHERE clause.   Therefore, mysqlnd_memcache can't intercept it. This will be executed   using the MySQL protocol*/$mysqli->query("SELECT id FROM test WHERE f1 = 'Lady'");while ($row = $result->fetch_row()) { print_r($row);}?> 

The above example will output:

array( [f1] => Hello [f2] => World [f3] => !)array( [id] => 2)

22.9.10.5. Installing/Configuring

Copyright 1997-2012 the PHP Documentation Group.

22.9.10.5.1. Requirements

Copyright 1997-2012 the PHP Documentation Group.

PHP: this extension requires PHP 5.4+, version PHP 5.4.4 or never. The required PHP extensions are PCRE (enabled by default), and the memcached extension version 2.0.x.

The mysqlnd_memcache Memcache plugin supports all PHP applications and all available PHP MySQL extensions (mysqli, mysql, PDO_MYSQL). The PHP MySQL extension must be configured with mysqlnd support.

For accessing InnoDB tables, this PHP extension requires MySQL Server 5.6.6 or newer with the InnoDB Memcache Daemon Plugin enabled.

For accessing MySQL Cluster NDB tables, this PHP extension requires MySQL Cluster 7.2 or newer with the NDB Memcache API nodes enabled.

22.9.10.5.2. Installation

Copyright 1997-2012 the PHP Documentation Group.

This PECL extension is not bundled with PHP.

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/mysqlnd_memcache

A DLL for this PECL extension is currently unavailable. See also the building on Windows section.

22.9.10.5.3. Runtime Configuration

Copyright 1997-2012 the PHP Documentation Group.

The behaviour of these functions is affected by settings in php.ini.

Table 22.76. Mysqlnd_memcache Configure Options

NameDefaultChangeableChangelog
mysqlnd_memcache.enable1PHP_INI_SYSTEMAvailable since 1.0.0

Here's a short explanation of the configuration directives.

mysqlnd_memcache.enable integer

Enables or disables the plugin. If disabled, the extension will not plug into mysqlnd to proxy internal mysqlnd C API calls.

Note

This option is mainly used by developers to build this extension statically into PHP. General users are encouraged to build this extension as a shared object, and to unload it completely when it is not needed.

22.9.10.6. Predefined Constants

Copyright 1997-2012 the PHP Documentation Group.

The constants below are defined by this extension, andwill only be available when the extension has eitherbeen compiled into PHP or dynamically loaded at runtime.

MySQL Memcache Plugin related

MYSQLND_MEMCACHE_DEFAULT_REGEXP (string)

Default regular expression (PCRE style) used for matching SELECT statements that will be mapped into a MySQL Memcache Plugin access point, if possible.

It is also possible to use mysqlnd_memcache_set, but the default approach is using this regular expression for pattern matching.

Assorted

The version number of this plugin can be obtained by using MYSQLND_MEMCACHE_VERSION or MYSQLND_MEMCACHE_VERSION_ID . MYSQLND_MEMCACHE_VERSION is the string representation of the numerical version number MYSQLND_MEMCACHE_VERSION_ID , which is an integer such as 10000. Developers can calculate the version number as follows.

Version (part)Example
Major*100001*10000 = 10000
Minor*1000*100 = 0
Patch0 = 0
MYSQLND_MEMCACHE_VERSION_ID10000

MYSQLND_MEMCACHE_VERSION (string)
Plugin version string, for example, "1.0.0-alpha".
MYSQLND_MEMCACHE_VERSION_ID (integer)
Plugin version number, for example, 10000.

22.9.10.7. Mysqlnd_memcache Functions

Copyright 1997-2012 the PHP Documentation Group.

22.9.10.7.1. mysqlnd_memcache_get_config

Copyright 1997-2012 the PHP Documentation Group.

  • mysqlnd_memcache_get_config

    Returns information about the plugin configuration

Description

array mysqlnd_memcache_get_config(mixed connection);

This function returns an array of all mysqlnd_memcache related configuration information that is attached to the MySQL connection. This includes MySQL, the Memcache object provided via mysqlnd_memcache_set, and the table mapping configuration that was automatically collected from the MySQL Server.

Parameters

connection

A handle to a MySQL Server using one of the MySQL API extensions for PHP, which are PDO_MYSQL, mysqli or ext/mysql.

Return Values

An array of mysqlnd_memcache configuration information on success, otherwise FALSE .

The returned array has these elements:

Table 22.77. mysqlnd_memcache_get_configarray structure

Array KeyDescription
memcachedInstance of Memcached associated to this MySQL connection by mysqlnd_memcache_set. You can use this to change settings of the memcache connection, or directly by querying the server on this connection.
patternThe PCRE regular expression used to match the SQL query sent to the server. Queries matching this pattern will be further analyzed to decide whether the query can be intercepted and sent via the memcache interface or whether the query is sent using the general MySQL protocol to the server. The pattern is either the default pattern (MYSQLND_MEMCACHE_DEFAULT_REGEXP) or it is set via mysqlnd_memcache_set.
mappingsAn associative array with a list of all configured containers as they were discovered by this plugin. The key for these elements is the name of the container in the MySQL configuration. The value is described below. The contents of this field is created by querying the MySQL Server during association to MySQL and a memcache connection using mysqlnd_memcache_set.
mapping_queryAn SQL query used during mysqlnd_memcache_set to identify the available containers and mappings. The result of that query is provided in the mappingselement.

Examples

Example 22.380. mysqlnd_memcache_get_configexample

<?php$mysqli = new mysqli("host", "user", "passwd", "database");$memc = new Memcached();$memc->addServer("host", 11211);mysqlnd_memcache_set($mysqli, $memc);var_dump(mysqlnd_memcache_get_config($mysqli));?> 

The above example will output:

array(4) {  ["memcached"]=>  object(Memcached)#2 (0) {  }  ["pattern"]=>  string(125) "/^\s*SELECT\s*(.+?)\s*FROM\s*`?([a-z0-9_]+)`?\s*WHERE\s*`?([a-z0-9_]+)`  ?\s*=\s*(?(?=["'])["']([^"']*)["']|([0-9e\.]*))\s*$/is"  ["mappings"]=>  array(1) { ["mymem_test"]=> array(6) {  ["prefix"]=>  string(13) "@@mymem_test."  ["schema_name"]=>  string(4) "test"  ["table_name"]=>  string(10) "mymem_test"  ["id_field_name"]=>  string(2) "id"  ["separator"]=>  string(1) "|"  ["fields"]=>  array(3) { [0]=> string(2) "f1" [1]=> string(2) "f2" [2]=> string(2) "f3"  } }  }  ["mapping_query"]=>  string(209) " SELECT c.name, CONCAT('@@', c.name, (SELECT value FROM  innodb_memcache.config_options WHERE name = 'table_map_delimiter')) AS key_prefix,  c.db_schema,  c.db_table,  c.key_columns,  c.value_columns,  (SELECT value FROM innodb_memcache.config_options WHERE name = 'separator') AS sep FROM innodb_memcache.containers c"}

See Also

mysqlnd_memcache_set
22.9.10.7.2. mysqlnd_memcache_set

Copyright 1997-2012 the PHP Documentation Group.

  • mysqlnd_memcache_set

    Associate a MySQL connection with a Memcache connection

Description

bool mysqlnd_memcache_set(mixed mysql_connection,
Memcached memcache_connection,
string pattern,
callback callback);

Associate mysql_connection with memcache_connection using pattern as a PCRE regular expression, and callback as a notification callback or to unset the association of mysql_connection.

While associating a MySQL connection with a Memcache connection, this function will query the MySQL Server for its configuration. It will automatically detect whether the server is configured to use the InnoDB Memcache Daemon Plugin or MySQL Cluster NDB Memcache support. It will also query the server to automatically identify exported tables and other configuration options. The results of this automatic configuration can be retrieved using mysqlnd_memcache_get_config.

Parameters

mysql_connection

A handle to a MySQL Server using one of the MySQL API extensions for PHP, which are PDO_MYSQL, mysqli or ext/mysql.

memcache_connection

A Memcached instance with a connection to the MySQL Memcache Daemon plugin. If this parameter is omitted, then mysql_connection will be unassociated from any memcache connection. And if a previous association exists, then it will be replaced.

pattern

A regular expression in Perl Compatible Regular Expression syntax used to identify potential Memcache-queries. The query should have three sub patterns. The first subpattern contains the requested field list, the second the name of the ID column from the query and the third the requested value. If this parameter is omitted or os set to NULL , then a default pattern will be used.

callback

A callback which will be used whenever a query is being sent to MySQL. The callback will receive a single boolean parameter telling if a query was sent via Memcache.

Return Values

TRUE if the association or disassociation is successful, otherwise FALSE if there is an error.

Examples

Example 22.381. mysqlnd_memcache_set example with var_dumpas a simple debugging callback.

<?php$mysqli = new mysqli("host", "user", "passwd", "database");$memc = new Memcached();$memc->addServer("host", 11211);mysqlnd_memcache_set($mysqli, $memc, NULL, 'var_dump');/* This query will be intercepted and executed via Memcache protocol */echo "Sending query for id via Memcache: ";$mysqli->query("SELECT f1, f2, f3 FROM test WHERE id = 1");/* f1 is not configured as valid key field, this won't be sent via Memcache */echo "Sending query for f1 via Memcache: ";$mysqli->query("SELECT id FROM test WHERE f1 = 1");mysqlnd_memcache_set($mysqli);/* Now the regular MySQL protocol will be used */echo "var_dump won't be invoked: ";$mysqli->query("SELECT f1, f2, f3 WHERE id = 1");?> 

The above example will output:

Sending query for id via Memcache: bool(true)Sending query for f1 via Memcache: bool(false)var_dump won't be invoked: 

See Also

mysqlnd_memcache_get_config

22.9.10.8. Change History

Copyright 1997-2012 the PHP Documentation Group.

This change history is a high level summary of selected changes that may impact applications and/or break backwards compatibility.

See also the CHANGES file in the source distribution for a complete list of changes.

22.9.10.8.1. PECL/mysqlnd_memcache 1.0 series

Copyright 1997-2012 the PHP Documentation Group.

1.0.0-alpha

  • Release date: TBD
  • Motto/theme: Basic mapping of SQL SELECT to a MySQL Memcache plugin access.

The initial release does map basic SQL SELECT statements to a MySQL Memcache plugin access. This bares potential performance benefits as the direct key-value access to MySQL storage using the Memcache protocol is usually faster than using SQL access.

22.9.11. Connector/PHP

This documentation, and other publications, sometimes uses the term Connector/PHP. This term refers to the full set of MySQL related functionality in PHP, which includes the three APIs that are described above, along with the mysqlnd core library and all of its plugins.

22.9.12. Common Problems with MySQL and PHP

  • Error: Maximum Execution Time Exceeded: This is a PHP limit; go into the php.ini file and set the maximum execution time up from 30 seconds to something higher, as needed. It is also not a bad idea to double the RAM allowed per script to 16MB instead of 8MB.

  • Fatal error: Call to unsupported or undefined function mysql_connect() in ...: This means that your PHP version isn't compiled with MySQL support. You can either compile a dynamic MySQL module and load it into PHP or recompile PHP with built-in MySQL support. This process is described in detail in the PHP manual.

  • Error: Undefined reference to 'uncompress': This means that the client library is compiled with support for a compressed client/server protocol. The fix is to add -lz last when linking with -lmysqlclient.

  • Error: Client does not support authentication protocol: This is most often encountered when trying to use the older mysql extension with MySQL 4.1.1 and later. Possible solutions are: downgrade to MySQL 4.0; switch to PHP 5 and the newer mysqli extension; or configure the MySQL server with the old_passwords system variable set to 1. (See Section C.5.2.4, "Client does not support authentication protocol", for more information.)

22.9.13. Enabling Both mysql and mysqli inPHP

If you're experiencing problems with enabling both the mysql and the mysqli extension when building PHP on Linux yourself, you should try the following procedure.

  1. Configure PHP like this:

    ./configure --with-mysqli=/usr/bin/mysql_config --with-mysql=/usr
  2. Edit the Makefile and search for a line that starts with EXTRA_LIBS. It might look like this (all on one line):

    EXTRA_LIBS = -lcrypt -lcrypt -lmysqlclient -lz -lresolv -lm -ldl -lnsl-lxml2 -lz -lm -lxml2 -lz -lm -lmysqlclient -lz -lcrypt -lnsl -lm-lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lcrypt
  3. Build and install PHP:

    makemake install
Copyright © 1997, 2013, Oracle and/or its affiliates. All rights reserved. Legal Notices
(Sebelumnya) 22.9.7. Mysqlnd query result c ...22.10. MySQL Perl API (Berikutnya)