Oracle 5.0 Reference Manual page 2582

Table of Contents

Advertisement

localhost. If on Unix like operating systems, the master on
client connections on the Unix domain socket /tmp/mysql.sock, while TCP/IP is the default port on
Windows. The plugin will use the user name
any of the MySQL servers listed in the section
the plugin will select
The username, password and schema name are taken from the connect API calls and used for all
servers. In other words: you must use the same username and password for every MySQL server
listed in a plugin configuration file section. The is not a general limitation. As of PECL/mysqlnd_ms
1.1.0, it is possible to set the
configuration file, to be used instead of the credentials passed to the API call.
The plugin does not change the API for running statements.
The following example assumes that there is no significant replication lag between the master and the
slave.
Example 20.221. Executing statements
<?php
/* Load balanced following "myapp" section rules from the plugins config file */
$mysqli = new mysqli("myapp", "username", "password", "database");
if (mysqli_connect_errno())
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
/* Statements will be run on the master */
if (!$mysqli->query("DROP TABLE IF EXISTS test")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
if (!$mysqli->query("CREATE TABLE test(id INT)")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
if (!$mysqli->query("INSERT INTO test(id) VALUES (1)")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
/* read-only: statement will be run on a slave */
if (!($res = $mysqli->query("SELECT id FROM test")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
} else {
$row = $res->fetch_assoc();
$res->close();
printf("Slave returns id = '%s'\n", $row['id'];
}
$mysqli->close();
?>
The above example will output something similar to:
Slave returns id = '1'
20.7.6.4.3. Connection state
Copyright 1997-2012 the PHP Documentation Group. [2230]
The plugin changes the semantics of a PHP MySQL connection handle. A new connection handle
represents a connection pool, instead of a single MySQL client-server network connection. The
connection pool consists of a master connection, and optionally any number of slave connections.
Every connection from the connection pool has its own state. For example, SQL user variables,
temporary tables and transactions are part of the state. For a complete list of items that belong to the
Mysqlnd replication and load balancing plugin (mysqlnd_ms)
as the current schemata.
database
username [2608]
localhost
and the password
username
of the plugins configuration file. Upon connect,
myapp
and
password [2608]
Read-write splitting
2562
will be accepting MySQL
to connect to
password
for any server in the plugins
works out of the box.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents