Ĭ������£����������������һ��������ʧ�ܵ�ʱ����й��ϴ�������Ϊ�˷�ֹ ����״̬�е����塣 ���ィ���ֶ��Ķ����Ӵ�����д�������Բ�������������½������ӣ�ִ�е���IJ�ѯ����ͬ����չʾ��������
�������״̬������������IJ�������ģ������ѡ���Զ����д���������������� ͨ�����ÿ���ʵ�֣��� master ���ֹ��ϣ��������������� master ֮ǰ���Զ��������� һ̨ slave ȥ�Զ�������ϣ������������������Ϊ �Զ�����ת�� ������һ��ʮ�ְ�ȫ�ķ�ʽ������Ͳ������������ˣ��� concepts section �л��и����˵����
Example #1 �ֶ�����ת�ƣ���ѡ�Զ�
{
"myapp": {
"master": {
"master_0": {
"host": "localhost",
"socket": "\/tmp\/mysql.sock"
}
},
"slave": {
"slave_0": {
"host": "simulate_slave_failure",
"port": "0"
},
"slave_1": {
"host": "127.0.0.1",
"port": 3311
}
},
"filters": { "roundrobin": [] }
}
}
Example #2 �ֶ�����ת��
<?php
$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()));
$sql = "SELECT 1 FROM DUAL";
/* error handling as it should be done regardless of the plugin */
if (!($res = $link->query($sql))) {
/* plugin specific: check for connection error */
switch ($link->errno) {
case 2002:
case 2003:
case 2005:
printf("Connection error - trying next slave!\n");
/* load balancer will pick next slave */
$res = $link->query($sql);
break;
default:
/* no connection error, failover is unlikely to help */
die(sprintf("SQL error: [%d] %s", $link->errno, $link->error));
break;
}
}
if ($res) {
var_dump($res->fetch_assoc());
}
?>