Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 2370

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Fetch the next row from a result set</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-execute.html">cubrid_execute</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-free-result.html">cubrid_free_result</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.cubrid-fetch" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_fetch</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.0)</p><p class="refpurpose"><span class="refname">cubrid_fetch</span> &mdash; <span class="dc-title">Fetch the next row from a result set</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-fetch-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>cubrid_fetch</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>  
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = CUBRID_BOTH</span></span>  
  ] )</div>

  <p class="para rdfs-comment">
    The  <span class="function"><strong>cubrid_fetch()</strong></span> function is used to get a single row from the query result.  The cursor automatically moves to the next row after getting the result.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.cubrid-fetch-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
  <dl>

    <dt>

  <span class="term"><em><code class="parameter">result</code></em></span>
  <dd>
<p class="para"><em><code class="parameter">result</code></em> comes from a call to  <span class="function"><a href="function.cubrid-execute.html" class="function">cubrid_execute()</a></span></p></dd>

   </dt>

   <dt>

  <span class="term"><em><code class="parameter">type</code></em></span>
  <dd>
<p class="para">Array type of the fetched result CUBRID_NUM, CUBRID_ASSOC,
    CUBRID_BOTH, CUBRID_OBJECT. If you want to operate the lob object, you can
    use CUBRID_LOB.</p></dd>

   </dt>

  </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.cubrid-fetch-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">Result array or object, when process is successful.</p>
  <p class="para"><strong><code>FALSE</code></strong>, when there are no more rows; NULL, when process is unsuccessful.</p>
  <p class="para">The result can be received either as an array or as an object, and you can decide which data type to use by setting the <em><code class="parameter">type</code></em> argument. The <em><code class="parameter">type</code></em> variable can be set to one of the following values:</p>
    <ul class="simplelist">
        <li class="member">CUBRID_NUM : Numerical array (0-based)</li>
        <li class="member">CUBRID_ASSOC : Associative array</li>
        <li class="member">CUBRID_BOTH : Numerical &amp; Associative array (default)</li>
        <li class="member">CUBRID_OBJECT : object that has the attribute name as the column name of query result</li>
    </ul>  
  <p class="para">When <em><code class="parameter">type</code></em> argument is omitted, the result will be received using CUBRID_BOTH option as default. When you want to receive query result in object data type, the column name of the result must obey the naming rules for identifiers in PHP.  For example, column name such as &quot;count(*)&quot; cannot be received in object type.</p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-fetch-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1018">
   <p><strong>Example #1  <span class="function"><strong>cubrid_fetch()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$req&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;stadium&nbsp;WHERE&nbsp;nation_code='GRE'&nbsp;AND&nbsp;seats&nbsp;&gt;&nbsp;10000"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-40s&nbsp;%-10s&nbsp;%-6s&nbsp;%-20s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"name"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"area"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"seats"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"address"</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">$row&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_fetch</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-40s&nbsp;%-10s&nbsp;%-6s&nbsp;%-20s\n"</span><span style="color: #007700">,&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"name"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"area"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"seats"</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$row</span><span style="color: #007700">[</span><span style="color: #DD0000">"address"</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;operate&nbsp;lob&nbsp;object,&nbsp;you&nbsp;can&nbsp;use&nbsp;cubrid_fetch($req,&nbsp;CUBRID_LOB)<br /><br /></span><span style="color: #0000BB">cubrid_close_request</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</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="cdata"><pre>
name                                     area       seats  address             
Panathinaiko Stadium                     86300.00   50000  Athens, Greece      
Olympic Stadium                          54700.00   13000  Athens, Greece      
Olympic Indoor Hall                      34100.00   18800  Athens, Greece      
Olympic Hall                             52400.00   21000  Athens, Greece      
Olympic Aquatic Centre                   42500.00   11500  Athens, Greece      
Markopoulo Olympic Equestrian Centre     64000.00   15000  Markopoulo, Athens, Greece
Faliro Coastal Zone Olympic Complex      34650.00   12171  Faliro, Athens, Greece
Athens Olympic Stadium                   120400.00  71030  Maroussi, Athens, Greece 
Ano Liossia                              34000.00   12000  Ano Liosia, Athens, Greece
</pre></div>
   </div>
  </div>
 </div>


    <div class="refsect1 seealso" id="refsect1-function.cubrid-fetch-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"> <span class="function"><a href="function.cubrid-execute.html" class="function" rel="rdfs-seeAlso">cubrid_execute()</a> - Execute a prepared SQL statement</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-fetch-array.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_array()</a> - Fetch a result row as an associative array, a numeric array, or both</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-fetch-row.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_row()</a> - Return a numerical array with the values of the current row</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-fetch-assoc.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_assoc()</a> - Return the associative array that corresponds to the fetched row</span></li>
   <li class="member"> <span class="function"><a href="function.cubrid-fetch-object.html" class="function" rel="rdfs-seeAlso">cubrid_fetch_object()</a> - Fetche the next row and returns it as an object</span></li>
   </ul>
  </p>
  </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.cubrid-execute.html">cubrid_execute</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.cubrid-free-result.html">cubrid_free_result</a></div>
 <div class="up"><a href="ref.cubrid.html">CUBRID Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>