PDO :: FETCH_ASSOC什么是PDO :: FETCH_ARRAY?

sop*_*hie 4 php pdo

<?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);
?>
Run Code Online (Sandbox Code Playgroud)

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

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

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

)
Run Code Online (Sandbox Code Playgroud)

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

Array
(
    [0] => Array
        (

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

    [1] => Array
        (

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

)
Run Code Online (Sandbox Code Playgroud)

Mus*_*usa 8

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

$result = $sth->fetchAll(PDO::FETCH_NUM);
Run Code Online (Sandbox Code Playgroud)

  • 来自http://php.net/manual/en/pdostatement.fetchall.php我没有看到有关FETCH_NUM选项的说法.随处可以使用您的提示.谢谢 (2认同)