<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.5 $ --> <refentry id="function.mysqli-multi-query"> <refnamediv> <refname>mysqli_multi_query</refname> <refname>mysqli->multi_query</refname> <refpurpose>Performs a query on the database</refpurpose> </refnamediv> <refsect1> <title>Description</title> <para>Procedural style:</para> <methodsynopsis> <type>bool</type><methodname>mysqli_multi_query</methodname> <methodparam><type>mysqli</type><parameter>link</parameter></methodparam> <methodparam><type>string</type><parameter>query</parameter></methodparam> </methodsynopsis> <para>Object oriented style (method):</para> <classsynopsis> <ooclass><classname>mysqli</classname></ooclass> <methodsynopsis> <type>bool</type><methodname>multi_query</methodname> <methodparam><type>string</type><parameter>query</parameter></methodparam> </methodsynopsis> </classsynopsis> <para> The <function>mysqli_multi_query</function> executes one or multiple queries which are concatenated by a semicolon. </para> <para> To retrieve the resultset from the first query you can use <function>mysqli_use_result</function> or <function>mysqli_store_result</function>. All subsequent query results can be processed using <function>mysqli_more_results</function> and <function>mysqli_next_result</function>. </para> </refsect1> <refsect1> &reftitle.returnvalues; <para> <function>mysqli_multi_query</function> only returns &false; if the first statement failed. To retrieve subsequent errors from other statements you have to call <function>mysqli_next_result</function> first. </para> </refsect1> <refsect1> &reftitle.seealso; <para> <function>mysqli_use_result</function>, <function>mysqli_store_result</function>, <function>mysqli_next_result</function>&listendand; <function>mysqli_more_results</function>. </para> </refsect1> <refsect1> &reftitle.examples; <example> <title>Object oriented style</title> <programlisting role="php"> <![CDATA[ <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT CURRENT_USER();"; $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5"; /* execute multi query */ if ($mysqli->multi_query($query)) { do { /* store first result set */ if ($result = $mysqli->store_result()) { while ($row = $result->fetch_row()) { printf("%s\n", $row[0]); } $result->close(); } /* print divider */ if ($mysqli->more_results()) { printf("-----------------\n"); } } while ($mysqli->next_result()); } /* close connection */ $mysqli->close(); ?> ]]> </programlisting> </example> <example> <title>Procedural style</title> <programlisting role="php"> <![CDATA[ <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT CURRENT_USER();"; $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5"; /* execute multi query */ if (mysqli_multi_query($link, $query)) { do { /* store first result set */ if ($result = mysqli_store_result($link)) { while ($row = mysqli_fetch_row($result)) { printf("%s\n", $row[0]); } mysqli_free_result($result); } /* print divider */ if (mysqli_more_results($link)) { printf("-----------------\n"); } } while (mysqli_next_result($link)); } /* close connection */ mysqli_close($link); ?> ]]> </programlisting> </example> &example.outputs; <screen> <![CDATA[ my_user@localhost ----------------- Amersfoort Maastricht Dordrecht Leiden Haarlemmermeer ]]> </screen> </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:"../../../../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 -->