4
<?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);
?>

上面的示例将获取结果集中所有剩余的行并输出类似于:

Array
(
    [0] => Array
        (
            [NAME] => pear
            [0] => pear
            [COLOUR] => green
            [1] => green
        )

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

)

是否有任何选项可以得到类似my_sql_fetch_array返回的结果,如下所示:

Array
(
    [0] => Array
        (

            [0] => pear
            [1] => green
        )

    [1] => Array
        (

            [0] => watermelon             
            [1] => pink
        )

)
4

2 回答 2

8

来自http://php.net/manual/en/pdostatement.fetch.php

$result = $sth->fetchAll(PDO::FETCH_NUM);
于 2012-06-16T23:11:25.043 回答
0

尝试使用这个

$data = $sth->fetch();
print_r($data);

希望它会帮助你。

于 2016-01-13T03:00:33.990 回答