PDOStatement::columnCount
PDOStatement::columnCount — 返回結果集中的列數。(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
說明
語法
int PDOStatement::columnCount ( void )
使用PDOStatement::columnCount()
返回由 PDOStatement 對象代表的結果集中的列數。
如果是由PDO::query()
返回的 PDOStatement 對象,則列數計算立即可用。
如果是由PDO::prepare()
返回的 PDOStatement 對象,則在調用PDOStatement::execute()
之前都不能準確地計算出列數。
返回值
返回由 PDOStatement 對象代表的結果集中的列數。如果沒有結果集,則PDOStatement::columnCount()
返回 0。
實例
計算列數
下面例子演示如何使用 PDOStatement::columnCount() 操作一個結果集和一個空集。
?php
$dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2');
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
/* 計算一個(不存在)的結果集中的列數 */
$colcount = $sth->columnCount();
print("Before execute(), result set has $colcount columns (should be 0)\n");
$sth->execute();
/* 計算結果集中的列數 */
$colcount = $sth->columnCount();
print("After execute(), result set has $colcount columns (should be 2)\n");
?>
以上例程會輸出:
Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
您可能感興趣的文章:- PHP PDOStatement::getColumnMeta講解
- PHP PDOStatement::getAttribute講解
- PHP PDOStatement::fetchObject講解
- PHP PDOStatement::fetchColumn講解
- PHP PDOStatement::fetchAll講解
- PHP PDOStatement::fetch講解
- PHP PDOStatement::execute講解
- PHP PDOStatement::errorInfo講解
- PHP PDOStatement::errorCode講解
- PHP PDOStatement::nextRowset講解