Oracle 5.0 Reference Manual page 2584

Table of Contents

Advertisement

connection to the master. The requested SQL user variable is not set. The example script prints
@myrole =
It is the responsibility of the application developer to take care of the connection state. The plugin does
not monitor all connection state changing activities. Monitoring all possible cases would be a very CPU
intensive task, if it could be done at all.
The pitfalls can easily be worked around using SQL hints.
20.7.6.4.4. SQL Hints
Copyright 1997-2012 the PHP Documentation Group. [2230]
SQL hints can force a query to choose a specific server from the connection pool. It gives the plugin a
hint to use a designated server, which can solve issues caused by connection switches and connection
state.
SQL hints are standard compliant SQL comments. Because SQL comments are supposed to be
ignored by SQL processing systems, they do not interfere with other programs such as the MySQL
Server, the MySQL Proxy, or a firewall.
Three SQL hints are supported by the plugin: The
plugin run a statement on the master,
and
MYSQLND_MS_LAST_USED_SWITCH
previous statement.
The plugin scans the beginning of a statement for the existence of an SQL hint. SQL hints are only
recognized if they appear at the beginning of the statement.
Example 20.224. Plugin config with one slave and one master
{
"myapp": {
"master": {
},
"slave": {
}
}
}
Example 20.225. SQL hints to prevent connection switches
<?php
$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()));
/* Connection 1, connection bound SQL user variable, no SELECT thus run on master */
if (!$mysqli->query("SET @myrole='master'")) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
}
/* Connection 1, run on master because of SQL hint */
if (!($res = $mysqli->query(sprintf("/*%s*/SELECT @myrole AS _role", MYSQLND_MS_LAST_USED_SWITCH)))) {
printf("[%d] %s\n", $mysqli->errno, $mysqli->error);
Mysqlnd replication and load balancing plugin (mysqlnd_ms)
''.
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
"slave_0": {
"host": "192.168.2.27",
"port": "3306"
}
MYSQLND_MS_MASTER_SWITCH
MYSQLND_MS_SLAVE_SWITCH
will run a statement on the same server that was used for the
2564
hint makes the
enforces the use of the slave,

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents