PHP PDOStatement::columnCount講解
PDOStatement::columnCount
PDOStatement::columnCount — 返回結(jié)果集中的列數(shù)。(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
說明
語法
int PDOStatement::columnCount ( void )
使用PDOStatement::columnCount()
返回由 PDOStatement 對象代表的結(jié)果集中的列數(shù)。
如果是由PDO::query()
返回的 PDOStatement 對象,則列數(shù)計(jì)算立即可用。
如果是由PDO::prepare()
返回的 PDOStatement 對象,則在調(diào)用PDOStatement::execute()
之前都不能準(zhǔn)確地計(jì)算出列數(shù)。
返回值
返回由 PDOStatement 對象代表的結(jié)果集中的列數(shù)。如果沒有結(jié)果集,則PDOStatement::columnCount()
返回 0。
實(shí)例
計(jì)算列數(shù)
下面例子演示如何使用 PDOStatement::columnCount() 操作一個(gè)結(jié)果集和一個(gè)空集。
<?php $dbh = new PDO('odbc:sample', 'db2inst1', 'ibmdb2'); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); /* 計(jì)算一個(gè)(不存在)的結(jié)果集中的列數(shù) */ $colcount = $sth->columnCount(); print("Before execute(), result set has $colcount columns (should be 0)\n"); $sth->execute(); /* 計(jì)算結(jié)果集中的列數(shù) */ $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)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
一個(gè)用于網(wǎng)絡(luò)的工具函數(shù)庫
一個(gè)用于網(wǎng)絡(luò)的工具函數(shù)庫...2006-10-10PHP中獲取文件創(chuàng)建日期、修改日期、訪問時(shí)間的方法
這篇文章主要介紹了PHP中獲取文件創(chuàng)建日期、修改日期、訪問時(shí)間的方法,有時(shí)候我們需要獲取頁面生成的時(shí)間,防止重復(fù)生成。需要的朋友可以參考下2016-11-11