PDO::query
PHP 教程
· 2019-01-28 17:57:01
PDO::query — 执行 SQL 语句,返回PDOStatement对象,可以理解为结果集(PHP 5 >= 5.1.0, PECL pdo >= 0.2.0)
说明
语法
public PDOStatement PDO::query ( string $statement )
public PDOStatement PDO::query ( string $statement , int $PDO::FETCH_COLUMN , int $colno )
public PDOStatement PDO::query ( string $statement , int $PDO::FETCH_CLASS , string $classname , array $ctorargs )
public PDOStatement PDO::query ( string $statement , int $PDO::FETCH_INTO , object $object )
PDO::query() 在一个单独的函数中调用并执行 SQL 语句, 返回结果集 (如果有),语句作为一个PDOStatement对象返回。
参数
statement
要执行的SQL语句。
返回值
如果成功,PDO::query()返回PDOStatement对象,如果失败返回 FALSE 。
实例
PDO::query实例
遍历输出结果集:
<?php function getFruit($conn) { $sql = 'SELECT name, color, calories FROM fruit ORDER BY name'; foreach ($conn->query($sql) as $row) { print $row['name'] . "\t"; print $row['color'] . "\t"; print $row['calories'] . "\n"; } } ?>
以上输出结果为:
apple red 150 banana yellow 250 kiwi brown 75 lemon yellow 25 orange orange 300 pear green 150 watermelon pink 90
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
Looking For a Challenge
the University of Warsaw / the University of Warsaw / 2012-11 / 0
LOOKING FOR PROGRAMMING CHALLENGES? Then this book is for you! Whether it's the feeling of great satisfaction from solving a complex problem set, or the frustration of being unable to solve a task,......一起来看看 《Looking For a Challenge》 这本书的介绍吧!