PHP中PDOStatement的columnCount方法具体返回了多少列?
- 内容介绍
- 文章标签
- 相关推荐
本文共计534个文字,预计阅读时间需要3分钟。
`PDOStatement::columnCount()` 返回一个 `PDOStatement` 对象中结果的列数。使用方法如下:
- 函数原型:`int PDOStatement::columnCount(void)`- 使用方式:通过传递一个 `PDOStatement` 对象给 `PDOStatement::columnCount()` 函数,可以得到该对象代表的结果集中的列数。
例如:php// 假设有一个PDOStatement对象 $stmt$columnCount=$stmt->columnCount();
echo 结果集中的列数是: . $columnCount;
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)
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对易盾网络的支持。如果你想了解更多相关内容请查看下面相关链接
本文共计534个文字,预计阅读时间需要3分钟。
`PDOStatement::columnCount()` 返回一个 `PDOStatement` 对象中结果的列数。使用方法如下:
- 函数原型:`int PDOStatement::columnCount(void)`- 使用方式:通过传递一个 `PDOStatement` 对象给 `PDOStatement::columnCount()` 函数,可以得到该对象代表的结果集中的列数。
例如:php// 假设有一个PDOStatement对象 $stmt$columnCount=$stmt->columnCount();
echo 结果集中的列数是: . $columnCount;
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)
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对易盾网络的支持。如果你想了解更多相关内容请查看下面相关链接

