pdostatement.columncount.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 101 行
HTML
101 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Returns the number of columns in the 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.closecursor.html">PDOStatement->closeCursor</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.errorcode.html">PDOStatement->errorCode</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.columncount" class="refentry"> <div class="refnamediv"> <h1 class="refname">PDOStatement->columnCount</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">PDOStatement->columnCount</span> — <span class="dc-title"> Returns the number of columns in the result set </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>PDOStatement::columnCount</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> Use <b>PDOStatement::columnCount()</b> to return the number of columns in the result set represented by the PDOStatement object. </p> <p class="para"> If the PDOStatement object was returned from <a href="pdo.query.html" class="function">PDO::query()</a>, the column count is immediately available. </p> <p class="para"> If the PDOStatement object was returned from <a href="pdo.prepare.html" class="function">PDO::prepare()</a>, an accurate column count will not be available until you invoke <a href="pdostatement.execute.html" class="function">PDOStatement::execute()</a>. </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the number of columns in the result set represented by the PDOStatement object. If there is no result set, <b>PDOStatement::columnCount()</b> returns <i>0</i>. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Counting columns</b></p> <div class="example-contents"><p> This example demonstrates how <b>PDOStatement::columnCount()</b> operates with and without a result set. </p></div> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$dbh </span><span style="color: #007700">= new </span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">'odbc:sample'</span><span style="color: #007700">, </span><span style="color: #DD0000">'db2inst1'</span><span style="color: #007700">, </span><span style="color: #DD0000">'ibmdb2'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$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 /><br /></span><span style="color: #FF8000">/* Count the number of columns in the (non-existent) result set */<br /></span><span style="color: #0000BB">$colcount </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">columnCount</span><span style="color: #007700">();<br />print(</span><span style="color: #DD0000">"Before execute(), result set has $colcount columns (should be 0)\n"</span><span style="color: #007700">);<br /><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">/* Count the number of columns in the result set */<br /></span><span style="color: #0000BB">$colcount </span><span style="color: #007700">= </span><span style="color: #0000BB">$sth</span><span style="color: #007700">-></span><span style="color: #0000BB">columnCount</span><span style="color: #007700">();<br />print(</span><span style="color: #DD0000">"After execute(), result set has $colcount columns (should be 2)\n"</span><span style="color: #007700">);<br /><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>Before execute(), result set has 0 columns (should be 0)After execute(), result set has 2 columns (should be 2)</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.prepare.html" class="function" rel="rdfs-seeAlso">PDO::prepare()</a></li> <li class="member"><a href="pdostatement.execute.html" class="function" rel="rdfs-seeAlso">PDOStatement::execute()</a></li> <li class="member"><a href="pdostatement.rowcount.html" class="function" rel="rdfs-seeAlso">PDOStatement::rowCount()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="pdostatement.closecursor.html">PDOStatement->closeCursor</a></div> <div class="next" style="text-align: right; float: right;"><a href="pdostatement.errorcode.html">PDOStatement->errorCode</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 + =
减小字号Ctrl + -
显示快捷键?