php-doc-en/reference/mysqlnd_ms/functions/mysqlnd-ms-query-is-select.xml
Yannick Torres 57236796d1 Fix svn keywords
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@310337 c90b9560-bf6c-de11-be94-00142212c4b1
2011-04-19 05:22:45 +00:00

139 lines
4.1 KiB
XML
Executable file

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.mysqlnd-ms-query-is-select" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>mysqlnd_ms_query_is_select</refname>
<refpurpose>Find whether to send the query to the master, the slave or the last used MySQL server</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>int</type>
<methodname>mysqlnd_ms_query_is_select</methodname>
<methodparam><type>string</type><parameter>query</parameter></methodparam>
</methodsynopsis>
<para>
Finds whether to send the query to the master, the slave or the
last used MySQL server.
</para>
<para>
The plugins built-in read/write split mechanism
will be used to analyze the query string to make a recommendation where
to send the query. The built-in read/write split mechanism is very
basic and simple. The plugin will recommend sending all queries to the
MySQL replication master server but those which begin with
<literal>SELECT</literal>, or begin with a SQL hint which
enforces sending the query to a slave server. Due to the basic
but fast algorithm the plugin may propose to run some read-only
statements such as <literal>SHOW TABLES</literal> on the replication master.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>query</parameter></term>
<listitem>
<para>
Query string to test.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A return value of <constant>MYSQLND_MS_QUERY_USE_MASTER</constant>
indicates that the query should be send to the MySQL replication
master server. The function returns a value of
<constant>MYSQLND_MS_QUERY_USE_SLAVE</constant> if the query can be run
on a slave because it is considered read-only. A value of
<constant>MYSQLND_MS_QUERY_USE_LAST_USED</constant> is returned to recommend
running the query on the last used server. This can either be a MySQL
replication master server or a MySQL replication slave server.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>mysqlnd_ms_query_is_select</function> example</title>
<programlisting role="php">
<![CDATA[
<?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");
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
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
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member>
<link linkend="mysqlnd-ms.constants">Predefined Constants</link>
</member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->