function.db2-fetch-object.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 152 行

HTML
152
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Returns an object with properties representing columns in the fetched row</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-fetch-both.html">db2_fetch_both</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-fetch-row.html">db2_fetch_row</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.db2-fetch-object" class="refentry"> <div class="refnamediv">  <h1 class="refname">db2_fetch_object</h1>  <p class="verinfo">(PECL ibm_db2:1.0-1.6.2)</p><p class="refpurpose"><span class="refname">db2_fetch_object</span> &mdash; <span class="dc-title">   Returns an object with properties representing columns in the fetched row  </span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">object</span> <span class="methodname"><b><b>db2_fetch_object</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$stmt</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$row_number</tt></span>  ] )</div>  <p class="para rdfs-comment">   Returns an object in which each property represents a column returned in   the row fetched from a result set.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">stmt</tt></i></span>     <dd>      <p class="para">       A valid <i>stmt</i> resource containing a result set.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">row_number</tt></i></span>     <dd>      <p class="para">       Requests a specific 1-indexed row from the result set. Passing this       parameter results in a PHP warning if the result set uses a       forward-only cursor.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns an object representing a single row in the result set. The   properties of the object map to the names of the columns in the result set.  </p>  <p class="para">   The IBM DB2, Cloudscape, and Apache Derby database servers typically fold   column names to upper-case, so the object properties will reflect that case.   </p>  <p class="para">   If your SELECT statement calls a scalar function to modify the value   of a column, the database servers return the column number as the name of   the column in the result set. If you prefer a more descriptive column name   and object property, you can use the AS clause to assign a name to the   column in the result set.  </p>  <p class="para">   Returns <b><tt>FALSE</tt></b> if no row was retrieved.  </p> </div><div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 A <b>db2_fetch_object()</b> example</b></p>    <div class="example-contents"><p>     The following example issues a SELECT statement with a scalar function,     RTRIM, that removes whitespace from the end of the column. Rather than     creating an object with the properties &quot;BREED&quot; and &quot;2&quot;, we use the AS     clause in the SELECT statement to assign the name &quot;name&quot; to the modified     column. The database server folds the column names to upper-case,     resulting in an object with the properties &quot;BREED&quot; and &quot;NAME&quot;.    </p></div>    <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">db2_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$database</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$user</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$password</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;breed,&nbsp;RTRIM(name)&nbsp;AS&nbsp;name<br />&nbsp;&nbsp;&nbsp;&nbsp;FROM&nbsp;animals<br />&nbsp;&nbsp;&nbsp;&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;?"</span><span style="color: #007700">;<br /><br />if&nbsp;(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_prepare</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">db2_execute</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(</span><span style="color: #0000BB">$pet&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">db2_fetch_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Come&nbsp;here,&nbsp;{$pet-&gt;NAME},&nbsp;my&nbsp;little&nbsp;{$pet-&gt;BREED}!"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">db2_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />}<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"><pre><div class="cdata"><pre>Come here, Pook, my little cat!</pre></div>    </pre></div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.db2-fetch-array.html" class="function" rel="rdfs-seeAlso">db2_fetch_array()</a></li>    <li class="member"><a href="function.db2-fetch-assoc.html" class="function" rel="rdfs-seeAlso">db2_fetch_assoc()</a></li>    <li class="member"><a href="function.db2-fetch-both.html" class="function" rel="rdfs-seeAlso">db2_fetch_both()</a></li>    <li class="member"><a href="function.db2-fetch-row.html" class="function" rel="rdfs-seeAlso">db2_fetch_row()</a></li>    <li class="member"><a href="function.db2-result.html" class="function" rel="rdfs-seeAlso">db2_result()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.db2-fetch-both.html">db2_fetch_both</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.db2-fetch-row.html">db2_fetch_row</a></div> <div class="up"><a href="ref.ibm-db2.html">IBM DB2 Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?