<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mysqli-stmt.fetch" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>mysqli_stmt::fetch</refname>
  <refname>mysqli_stmt_fetch</refname>
  <refpurpose>Fetch results from a prepared statement into the bound variables</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <para>&style.oop;</para>
  <methodsynopsis role="mysqli_stmt">
   <modifier>public</modifier> <type class="union"><type>bool</type><type>null</type></type><methodname>mysqli_stmt::fetch</methodname>
   <void/>
  </methodsynopsis>
  <para>&style.procedural;</para>
  <methodsynopsis>
   <type class="union"><type>bool</type><type>null</type></type><methodname>mysqli_stmt_fetch</methodname>
   <methodparam><type>mysqli_stmt</type><parameter>statement</parameter></methodparam>
  </methodsynopsis>
  <para>
   Fetch the result from a prepared statement into the variables bound by
   <function>mysqli_stmt_bind_result</function>.
  </para>
  <note>
   <para>
    Note that all columns must be bound by the application before calling
    <function>mysqli_stmt_fetch</function>.
   </para>
  </note>
  <note>
   <para>
    Data are transferred unbuffered without calling
    <function>mysqli_stmt_store_result</function> which can decrease
    performance (but reduces memory cost).
   </para>
  </note>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    &mysqli.stmt.description;
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <table xml:id="mysqli-stmt.fetch.returnvalues">
   &reftitle.returnvalues;
   <tgroup cols="2">
    <thead>
     <row>
      <entry>Value</entry>
      <entry>Description</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>&true;</entry>
      <entry>Success. Data has been fetched</entry>
     </row>
     <row>
      <entry>&false;</entry>
      <entry>Error occurred</entry>
     </row>
     <row>
      <entry>&null;</entry>
      <entry>No more rows/data exists or data truncation occurred</entry>
     </row>
    </tbody>
   </tgroup>
  </table>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  &mysqli.conditionalexception;
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title>&style.oop;</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 Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = $mysqli->prepare($query)) {

    /* execute statement */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($name, $code);

    /* fetch values */
    while ($stmt->fetch()) {
        printf ("%s (%s)\n", $name, $code);
    }

    /* close statement */
    $stmt->close();
}

/* close connection */
$mysqli->close();
?>
]]>
   </programlisting>
  </example>
  <example>
   <title>&style.procedural;</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 Name, CountryCode FROM City ORDER by ID DESC LIMIT 150,5";

if ($stmt = mysqli_prepare($link, $query)) {

    /* execute statement */
    mysqli_stmt_execute($stmt);

    /* bind result variables */
    mysqli_stmt_bind_result($stmt, $name, $code);

    /* fetch values */
    while (mysqli_stmt_fetch($stmt)) {
        printf ("%s (%s)\n", $name, $code);
    }

    /* close statement */
    mysqli_stmt_close($stmt);
}

/* close connection */
mysqli_close($link);
?>
]]>
   </programlisting>
   &examples.outputs;
   <screen>
<![CDATA[
Rockford (USA)
Tallahassee (USA)
Salinas (USA)
Santa Clarita (USA)
Springfield (USA)
]]>
   </screen>
  </example>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>mysqli_prepare</function></member>
    <member><function>mysqli_stmt_errno</function></member>
    <member><function>mysqli_stmt_error</function></member>
    <member><function>mysqli_stmt_bind_result</function></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
-->
