PHP PDOStatement::fetchColumn讲解
作者:php参考手册 时间:2023-06-06 09:17:20
PDOStatement::fetchColumn
PDOStatement::fetchColumn — 从结果集中的下一行返回单独的一列。(PHP 5 >= 5.1.0, PECL pdo >= 0.9.0)
说明
语法
string PDOStatement::fetchColumn ([ int $column_number = 0 ] )
从结果集中的下一行返回单独的一列,如果没有了,则返回 FALSE 。
参数
column_number
你想从行里取回的列的索引数字(以0开始的索引)。如果没有提供值,则 PDOStatement::fetchColumn() 获取第一列。
返回值
PDOStatement::fetchColumn()
从结果集中的下一行返回单独的一列。
注意:如果使用PDOStatement::fetchColumn() 取回数据,则没有办法返回同一行的另外一列。**
实例
返回下一行的第一列
<?php
$sth = $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();
/* 从结果集中的下一行获取第一列 */
print("从结果集中的下一行获取第一列:\n");
$result = $sth->fetchColumn();
print("name = $result\n");
print("从结果集中的下一行获取第二列:\n");
$result = $sth->fetchColumn(1);
print("colour = $result\n");
?>
以上实例会输出:
从结果集中的下一行获取第一列:
name = lemon
从结果集中的下一行获取第二列:
colour = red
标签:php,pdostatement,fetchcolumn
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Keras搭建Efficientdet目标检测平台的实现思路
2022-01-18 21:07:31
![](https://img.aspxhome.com/file/2023/6/131836_0s.jpg)
Python自定义聚合函数merge与transform区别详解
2022-09-14 11:45:30
python学习必备知识汇总
2022-01-05 10:26:23
基于Python+Pygame实现经典赛车游戏
2023-09-18 03:57:43
![](https://img.aspxhome.com/file/2023/9/135429_0s.jpg)
vue项目打包后怎样优雅的解决跨域
2024-04-29 13:11:03
asp base64加解密函数代码
2011-03-31 11:02:00
Python3实现爬取简书首页文章标题和文章链接的方法【测试可用】
2021-10-08 00:22:10
![](https://img.aspxhome.com/file/2023/4/89334_0s.png)
Python 多张图片合并成一个pdf的参考示例
2021-10-15 23:32:45
javascript之学会吝啬 精简代码
2024-04-19 09:52:21
区别JavaScript函数声明与变量声明
2024-04-18 09:34:42
利用Python实现RSA加密解密方法实例
2023-10-07 03:10:58
![](https://img.aspxhome.com/file/2023/7/130997_0s.png)
python pandas写入excel文件的方法示例
2022-02-27 05:04:14
Python headers请求头如何实现快速添加
2023-04-11 15:24:26
![](https://img.aspxhome.com/file/2023/1/133271_0s.png)
pandas时间序列之如何将int转换成datetime格式
2023-03-09 07:50:34
![](https://img.aspxhome.com/file/2023/1/84061_0s.png)
Firefox window.close()的使用注意事项
2024-04-17 10:11:12
python正则表达式判断字符串是否是全部小写示例
2021-10-10 08:37:40
编写Python脚本来实现最简单的FTP下载的教程
2022-11-12 01:25:45
Python使用base64模块进行二进制数据编码详解
2023-08-26 20:13:13
Python实现五子棋联机对战小游戏
2023-10-21 05:25:42
![](https://img.aspxhome.com/file/2023/4/120914_0s.gif)
python实现飞机大战
2021-03-05 04:19:26
![](https://img.aspxhome.com/file/2023/8/97388_0s.jpg)