PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<PDOStatement::fetchPDOStatement::fetchColumn>
Last updated: Mon, 16 Jul 2012

PDOStatement::fetchAll

(no version information, might be only in CVS)

PDOStatement::fetchAll --  Returns an array containing all of the result set rows

说明

array PDOStatement::fetchAll ( [int fetch_style] )

警告

本函数是实验性的。本函数的行为,包括函数名称以及其它任何关于本函数的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本函数风险自担。

参数

fetch_style

Controls the contents of the returned array as documented in PDOStatement::fetch(). Defaults to PDO_FETCH_BOTH.

返回值

PDOStatement::fetchAll() returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name.

Using this method to fetch large result sets will result in a heavy demand on system and possibly network resources. Rather than retrieving all of the data and manipulating it in PHP, consider using the database server to manipulate the result sets. For example, use the WHERE and SORT BY clauses in SQL to restrict results before retrieving and processing them with PHP.

例子 1. Fetch all remaining rows in a result set

<?php
$sth
= $dbh->prepare("SELECT name, colour FROM fruit");
$sth->execute();

/* Fetch all of the remaining rows in the result set */
print("Fetch all of the remaining rows in the result set:\n");
$result = $sth->fetchAll();
print_r($result);
?>

上例将输出:

Fetch all of the remaining rows in the result set:
Array
(
    [0] => Array
        (
            [NAME] => pear
            [0] => pear
            [COLOUR] => green
            [1] => green
        )

    [1] => Array
        (
            [NAME] => watermelon
            [0] => watermelon
            [COLOUR] => pink
            [1] => pink
        )

)

参见

PDO::query()
PDOStatement::fetch()
PDOStatement::fetchColumn()
PDOStatement::prepare()
PDOStatement::setFetchMode()




<PDOStatement::fetchPDOStatement::fetchColumn>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST