Oracle 5.0 Reference Manual page 2588

Table of Contents

Advertisement

$mysqli = new mysqli("myapp", "username", "password", "database");
if (!$mysqli)
/* Of course, your error handling is nicer... */
die(sprintf("[%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()));
/* Disable autocommit, plugin will run all statements on the master */
$mysqli->autocommit(FALSE);
if (!$mysqli->query("INSERT INTO test(id) VALUES (1)")) {
/* Please do proper ROLLBACK in your code, don't just die */
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if ($res = $mysqli->query("SELECT COUNT(*) AS _num FROM test")) {
$row = $res->fetch_assoc();
$res->close();
if ($row['_num'] > 1000) {
if (!$mysqli->query("INSERT INTO events(task) VALUES ('cleanup')")) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
}
} else {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if (!$mysqli->query("UPDATE log SET last_update = NOW()")) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
if (!$mysqli->commit()) {
die(sprintf("[%d] %s\n", $mysqli->errno, $mysqli->error));
}
/* Plugin assumes that the transaction has ended and starts load balancing again */
$mysqli->autocommit(TRUE);
$mysqli->close();
?>
Please note the restrictions outlined in the
20.7.6.4.6. Service level and consistency
Copyright 1997-2012 the PHP Documentation Group. [2230]
Different types of MySQL cluster solutions offer different service and data consistency levels to their
users. An asynchronous MySQL replication cluster offers eventual consistency by default. A read
executed on an asynchronous slave may return current, stale or no data at all, depending on whether
the slave has replayed all changesets from the master or not.
Applications using an MySQL replication cluster need to be designed to work correctly with eventual
consistent data. In some cases, however, stale data is not acceptable. In those cases only certain
slaves or even only master accesses are allowed to achieve the required quality of service from the
cluster.
As of PECL mysqlnd_ms 1.2.0 the plugin is capable of selecting MySQL replication nodes
automatically that deliver session consistency or strong consistency. Session consistency means that
one client can read its writes. Other clients may or may not see the clients' write. Strong consistency
means that all clients will see all writes from the client.
Mysqlnd replication and load balancing plugin (mysqlnd_ms)
Version requirement
The plugin configuration option
newer.
Version requirement
Service levels have been introduced in PECL mysqlnd_ms version 1.2.0-alpha.
mysqlnd_ms_set_qos
trx_stickiness=master
transaction handling
concepts section.
is available with PHP 5.4.0 or newer.
2568
requires PHP 5.4.0 or

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents