📄 pdostatement.fetchcolumn.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns a single column from the next row of a result set</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="pdostatement.fetchall.html">PDOStatement->fetchAll</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.fetchobject.html">PDOStatement->fetchObject</a></div> <div class="up"><a href="class.pdostatement.html">PDOStatement</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="pdostatement.fetchcolumn" class="refentry"> <div class="refnamediv"> <h1 class="refname">PDOStatement->fetchColumn</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">PDOStatement->fetchColumn</span> — <span class="dc-title"> Returns a single column from the next row of a result set </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>PDOStatement::fetchColumn</b></b></span> ([ <span class="methodparam"><span class="type">int</span> <tt class="parameter">$column_number</tt></span> ] )</div> <p class="para rdfs-comment"> Returns a single column from the next row of a result set or <b><tt>FALSE</tt></b> if there are no more rows. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">column_number</tt></i></span> <dd> <p class="para"> 0-indexed number of the column you wish to retrieve from the row. If no value is supplied, <b>PDOStatement::fetchColumn()</b> fetches the first column. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> <b>PDOStatement::fetchColumn()</b> returns a single column in the next row of a result set. </p> <div class="warning"><b class="warning">Warning</b> <p class="para"> There is no way to return another column from the same row if you use <b>PDOStatement::fetchColumn()</b> to retrieve data. </p> </div> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"><p><b>Example #1 Return first column of the next row</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$sth </span><span style="color: #007700">= </span><span style="color: #0000BB">$dbh</span><span style="color: #007700">-></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">-></span><span style="color: #0000BB">execute</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">/* Fetch the first column from the next row in the result set */<br /></span><span style="color: #007700">print(</span><span style="color: #DD0000">"Fetch the first column from the next row in the result set:\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">-></span><span style="color: #0000BB">fetchColumn</span><span style="color: #007700">();<br />print(</span><span style="color: #DD0000">"name = $result\n"</span><span style="color: #007700">);<br /><br />print(</span><span style="color: #DD0000">"Fetch the second column from the next row in the result set:\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">-></span><span style="color: #0000BB">fetchColumn</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br />print(</span><span style="color: #DD0000">"colour = $result\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></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>Fetch the first column from the next row in the result set:name = lemonFetch the second column from the next row in the result set:colour = red</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="pdo.query.html" class="function" rel="rdfs-seeAlso">PDO::query()</a></li> <li class="member"><a href="pdostatement.fetch.html" class="function" rel="rdfs-seeAlso">PDOStatement::fetch()</a></li> <li class="member"><a href="pdostatement.fetchall.html" class="function" rel="rdfs-seeAlso">PDOStatement::fetchAll()</a></li> <li class="member"><a href="pdo.prepare.html" class="function" rel="rdfs-seeAlso">PDO::prepare()</a></li> <li class="member"><a href="pdostatement.setfetchmode.html" class="function" rel="rdfs-seeAlso">PDOStatement::setFetchMode()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdostatement.fetchall.html">PDOStatement->fetchAll</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.fetchobject.html">PDOStatement->fetchObject</a></div> <div class="up"><a href="class.pdostatement.html">PDOStatement</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -