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」不依赖集成环境,使用Nginx手动配置Thinkphp运行环境
如何安装linux mint,和windows10组成双系统?
网友评论