(PECL mysqlnd_ms >= 1.0.0)
mysqlnd_ms_query_is_select — ��ѯ������ SQL �ᷢ�� master��slave �������ʹ�õ� MySQL server ִ�С�
$query
) : int��ѯ������ SQL �ᷢ�� master��slave �������ʹ�õ� MySQL server ִ�С�
������õĶ�д�������� SQL��Ȼ��������װ������͵�����ִ�С������д�������dz� �Ļ����ͼ�����Ὣ���еIJ�ѯ���� master���������� SELECT ��ͷ������ʹ�� SQL hints ָ��Ҫȥ slave ִ�С���Ϊ�����д����ܼ� ���ԻὫһЩֻ����ѯ��������ͬ���� master�����磺SHOW TABLES��
query
Ҫ���Ե� SQL �ַ�����
���� MYSQLND_MS_QUERY_USE_MASTER
˵������ master��
���� MYSQLND_MS_QUERY_USE_SLAVE
˵����һ��ֻ����䣬
������ slave ִ�С����� MYSQLND_MS_QUERY_USE_LAST_USED
˵��������һ��ִ�еķ�����������ִ�У�������� master Ҳ������ slave��
���ͨ���趨 mysqlnd_ms.disable_rw_split �����˶�д���룬
��ô�������ܷ��� MYSQLND_MS_QUERY_USE_MASTER
���߷���
MYSQLND_MS_QUERY_USE_LAST_USED
��
Example #1 mysqlnd_ms_query_is_select() example
<?php
function is_select($query)
{
switch (mysqlnd_ms_query_is_select($query))
{
case MYSQLND_MS_QUERY_USE_MASTER:
printf("'%s' should be run on the master.\n", $query);
break;
case MYSQLND_MS_QUERY_USE_SLAVE:
printf("'%s' should be run on a slave.\n", $query);
break;
case MYSQLND_MS_QUERY_USE_LAST_USED:
printf("'%s' should be run on the server that has run the previous query\n", $query);
break;
default:
printf("No suggestion where to run the '%s', fallback to master recommended\n", $query);
break;
}
}
is_select("INSERT INTO test(id) VALUES (1)");
is_select("SELECT 1 FROM DUAL");
is_select("/*" . MYSQLND_MS_LAST_USED_SWITCH . "*/SELECT 2 FROM DUAL");
?>
�������̻������
INSERT INTO test(id) VALUES (1) should be run on the master. SELECT 1 FROM DUAL should be run on a slave. /*ms=last_used*/SELECT 2 FROM DUAL should be run on the server that has run the previous query