<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.pdostatement.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'pdostatement.fetch.php',
    1 => 'PDOStatement::fetch',
    2 => 'Fetches the next row from a result set',
  ),
  'up' => 
  array (
    0 => 'class.pdostatement.php',
    1 => 'PDOStatement',
  ),
  'prev' => 
  array (
    0 => 'pdostatement.execute.php',
    1 => 'PDOStatement::execute',
  ),
  'next' => 
  array (
    0 => 'pdostatement.fetchall.php',
    1 => 'PDOStatement::fetchAll',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/pdo/pdostatement/fetch.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="pdostatement.fetch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">PDOStatement::fetch</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8, PECL pdo &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">PDOStatement::fetch</span> &mdash; <span class="dc-title">
   Fetches the next row from a result set
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-pdostatement.fetch-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>PDOStatement::fetch</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code><a href="pdo.constants.fetch-modes.php#pdo.constants.fetch-default">PDO::FETCH_DEFAULT</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$cursorOrientation</code><span class="initializer"> = <strong><code><a href="pdo.constants.php#pdo.constants.fetch-ori-next">PDO::FETCH_ORI_NEXT</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$cursorOffset</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>


  <p class="para rdfs-comment">
   Fetches a row from a result set associated with a PDOStatement object. The
   <code class="parameter">mode</code> parameter determines how PDO returns
   the row.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-pdostatement.fetch-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">mode</code></dt>
     <dd>
      <p class="para">
       Controls how the next row will be returned to the caller. This value
       must be one of the <code class="literal">PDO::FETCH_*</code> constants,
       defaulting to value of <code class="literal">PDO::ATTR_DEFAULT_FETCH_MODE</code>
       (which defaults to <code class="literal">PDO::FETCH_BOTH</code>).
       <ul class="itemizedlist">
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_ASSOC</code>: returns an array indexed by column
         name as returned in your result set
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_BOTH</code> (default): returns an array indexed by
         both column name and 0-indexed column number as returned in your
         result set
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_BOUND</code>: returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> and assigns the
         values of the columns in your result set to the PHP variables to which
         they were bound with the <span class="methodname"><a href="pdostatement.bindcolumn.php" class="methodname">PDOStatement::bindColumn()</a></span>
         method
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_CLASS</code>: returns a new instance of the
         requested class. The object is initialized by mapping the columns of
         the result set to properties in the class. This occurs before the
         constructor is called, allowing properties to be populated regardless
         of their visibility or whether they are marked as <code class="literal">readonly</code>.
         If a property does not exist in the class, the magic <a href="language.oop5.overloading.php#object.set" class="link">__set()</a>
         method will be invoked if it exists; otherwise, a dynamic public
         property will be created. However, when <strong><code><a href="pdo.constants.fetch-modes.php#pdo.constants.fetch-props-late">PDO::FETCH_PROPS_LATE</a></code></strong>
         is also given, the constructor is called <em>before</em>
         the properties are populated. If <code class="parameter">mode</code> includes
         <strong><code><a href="pdo.constants.fetch-modes.php#pdo.constants.fetch-classtype">PDO::FETCH_CLASSTYPE</a></code></strong> (e.g.
         <code class="literal">PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE</code>), the name
         of the class is determined from the value of the first column.
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_INTO</code>: updates an existing instance
         of the requested class, mapping the columns of the result set to
         named properties in the class
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_LAZY</code>: combines
         <code class="literal">PDO::FETCH_BOTH</code> and <code class="literal">PDO::FETCH_OBJ</code>,
         and is returning a <span class="classname"><a href="class.pdorow.php" class="classname">PDORow</a></span> object
         which is creating the object property names as they are accessed.
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_NAMED</code>: returns an array with the same
         form as <code class="literal">PDO::FETCH_ASSOC</code>, except that if there are
         multiple columns with the same name, the value referred to by that
         key will be an array of all the values in the row that had that
         column name
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_NUM</code>: returns an array indexed by column
         number as returned in your result set, starting at column 0
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_OBJ</code>: returns an anonymous object with
         property names that correspond to the column names returned in your
         result set
        </p></li>
        <li class="listitem"><p class="para">
         <code class="literal">PDO::FETCH_PROPS_LATE</code>: when used with
         <code class="literal">PDO::FETCH_CLASS</code>, the constructor of the class is
         called before the properties are assigned from the respective column
         values.
        </p></li>
       </ul>
      </p>
     </dd>
    
    
     <dt><code class="parameter">cursorOrientation</code></dt>
     <dd>
      <p class="para">
       For a PDOStatement object representing a scrollable cursor, this
       value determines which row will be returned to the caller. This value
       must be one of the <code class="literal">PDO::FETCH_ORI_*</code> constants,
       defaulting to <code class="literal">PDO::FETCH_ORI_NEXT</code>. To request a
       scrollable cursor for your PDOStatement object, you must set the
       <code class="literal">PDO::ATTR_CURSOR</code> attribute to
       <code class="literal">PDO::CURSOR_SCROLL</code> when you prepare the SQL
       statement with <span class="methodname"><a href="pdo.prepare.php" class="methodname">PDO::prepare()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">cursorOffset</code></dt>
     <dd>
      <p class="para">
       For a PDOStatement object representing a scrollable cursor for which
       the <code class="parameter">cursorOrientation</code> parameter is set to
       <code class="literal">PDO::FETCH_ORI_ABS</code>, this value specifies the
       absolute number of the row in the result set that shall be fetched.
      </p>
      <p class="para">
       For a PDOStatement object representing a scrollable cursor for which
       the <code class="parameter">cursorOrientation</code> parameter is set to
       <code class="literal">PDO::FETCH_ORI_REL</code>, this value specifies the
       row to fetch relative to the cursor position before
       <span class="methodname"><strong>PDOStatement::fetch()</strong></span> was called.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-pdostatement.fetch-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   The return value of this function on success depends on the fetch type. In
   all cases, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned on failure or if there are no more rows.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-pdostatement.fetch-errors">
  <h3 class="title">Errors/Exceptions</h3>
  <p class="para">
Emits an error with level <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong> is set
to <strong><code><a href="pdo.constants.php#pdo.constants.errmode-warning">PDO::ERRMODE_WARNING</a></code></strong>.
</p>
<p class="para">
Throws a <span class="classname"><a href="class.pdoexception.php" class="classname">PDOException</a></span> if the attribute <strong><code><a href="pdo.constants.php#pdo.constants.attr-errmode">PDO::ATTR_ERRMODE</a></code></strong>
is set to <strong><code><a href="pdo.constants.php#pdo.constants.errmode-exception">PDO::ERRMODE_EXCEPTION</a></code></strong>.
</p>
 </div>


 <div class="refsect1 examples" id="refsect1-pdostatement.fetch-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1"><p><strong>Example #1 Fetching rows using different fetch styles</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT name, colour FROM fruit"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Exercise PDOStatement::fetch styles */<br /></span><span style="color: #007700">print </span><span style="color: #DD0000">"PDO::FETCH_ASSOC: "</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Return next row as an array indexed by column name\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_ASSOC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />print </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"PDO::FETCH_BOTH: "</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Return next row as an array indexed by both column name and number\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_BOTH</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />print </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"PDO::FETCH_LAZY: "</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Return next row as a PDORow object with column names as properties\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_LAZY</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />print </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"PDO::FETCH_OBJ: "</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"Return next row as an anonymous object with column names as properties\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_OBJ</span><span style="color: #007700">);<br />print </span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">;<br />print </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">PDO::FETCH_ASSOC: Return next row as an array indexed by column name
Array
(
    [name] =&gt; apple
    [colour] =&gt; red
)

PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number
Array
(
    [name] =&gt; banana
    [0] =&gt; banana
    [colour] =&gt; yellow
    [1] =&gt; yellow
)

PDO::FETCH_LAZY: Return next row as a PDORow object with column names as properties
PDORow Object
(
    [name] =&gt; orange
    [colour] =&gt; orange
)

PDO::FETCH_OBJ: Return next row as an anonymous object with column names as properties
kiwi</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2"><p><strong>Example #2 Fetching rows with a scrollable cursor</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">readDataForwards</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">'SELECT hand, won, bet FROM mynumbers ORDER BY BET'</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">, array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_CURSOR </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">CURSOR_SCROLL</span><span style="color: #007700">));<br />    </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br />    while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_NUM</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_ORI_NEXT</span><span style="color: #007700">)) {<br />        </span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />        print </span><span style="color: #0000BB">$data</span><span style="color: #007700">;<br />    }<br />}<br />function </span><span style="color: #0000BB">readDataBackwards</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbh</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">'SELECT hand, won, bet FROM mynumbers ORDER BY bet'</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$stmt </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">, array(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">ATTR_CURSOR </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">CURSOR_SCROLL</span><span style="color: #007700">));<br />    </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br />    </span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_NUM</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_ORI_LAST</span><span style="color: #007700">);<br />    do {<br />        </span><span style="color: #0000BB">$data </span><span style="color: #007700">= </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\t" </span><span style="color: #007700">. </span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">] . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />        print </span><span style="color: #0000BB">$data</span><span style="color: #007700">;<br />    } while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">$stmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_NUM</span><span style="color: #007700">, </span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_ORI_PRIOR</span><span style="color: #007700">));<br />}<br /><br />print </span><span style="color: #DD0000">"Reading forwards:\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">readDataForwards</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br />print </span><span style="color: #DD0000">"Reading backwards:\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">readDataBackwards</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Reading forwards:
21    10    5
16    0     5
19    20    10

Reading backwards:
19    20    10
16    0     5
21    10    5</pre>
</div>
    </div>
   </div>

   <div class="example" id="example-3"><p><strong>Example #3 Construction order</strong></p>
    <div class="example-contents"><p>
     When objects are fetched via <strong><code><a href="pdo.constants.fetch-modes.php#pdo.constants.fetch-class">PDO::FETCH_CLASS</a></code></strong>, the object
     properties are assigned first, and then the constructor of the class is
     invoked. However, when <strong><code><a href="pdo.constants.fetch-modes.php#pdo.constants.fetch-props-late">PDO::FETCH_PROPS_LATE</a></code></strong> is also given,
     this order is reversed, i.e. first the constructor is called, and
     afterwards the properties are assigned.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Person<br /></span><span style="color: #007700">{<br />    private </span><span style="color: #0000BB">$name</span><span style="color: #007700">;<br /><br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">()<br />    {<br />        </span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">tell</span><span style="color: #007700">();<br />    }<br /><br />    public function </span><span style="color: #0000BB">tell</span><span style="color: #007700">()<br />    {<br />        if (isset(</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">)) {<br />            echo </span><span style="color: #DD0000">"I am </span><span style="color: #007700">{</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">name</span><span style="color: #007700">}</span><span style="color: #DD0000">.\n"</span><span style="color: #007700">;<br />        } else {<br />            echo </span><span style="color: #DD0000">"I don't have a name yet.\n"</span><span style="color: #007700">;<br />        }<br />    }<br />}<br /><br /></span><span style="color: #0000BB">$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT * FROM people"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFetchMode</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_CLASS</span><span style="color: #007700">, </span><span style="color: #DD0000">'Person'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$person </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$person</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">tell</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setFetchMode</span><span style="color: #007700">(</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_CLASS</span><span style="color: #007700">|</span><span style="color: #0000BB">PDO</span><span style="color: #007700">::</span><span style="color: #0000BB">FETCH_PROPS_LATE</span><span style="color: #007700">, </span><span style="color: #DD0000">'Person'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$person </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$person</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">tell</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">I am Alice.
I am Alice.
I don&#039;t have a name yet.
I am Bob.</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-pdostatement.fetch-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="pdo.prepare.php" class="methodname" rel="rdfs-seeAlso">PDO::prepare()</a> - Prepares a statement for execution and returns a statement object</span></li>
    <li><span class="methodname"><a href="pdostatement.execute.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::execute()</a> - Executes a prepared statement</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchall.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchAll()</a> - Fetches the remaining rows from a result set</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchcolumn.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchColumn()</a> - Returns a single column from the next row of a result set</span></li>
    <li><span class="methodname"><a href="pdostatement.fetchobject.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::fetchObject()</a> - Fetches the next row and returns it as an object</span></li>
    <li><span class="methodname"><a href="pdostatement.setfetchmode.php" class="methodname" rel="rdfs-seeAlso">PDOStatement::setFetchMode()</a> - Set the default fetch mode for this statement</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>