<?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
)
)
答案 0 :(得分:8)
来自http://php.net/manual/en/pdostatement.fetch.php
$result = $sth->fetchAll(PDO::FETCH_NUM);
答案 1 :(得分:0)
尝试使用此
$data = $sth->fetch();
print_r($data);
希望它会对你有所帮助。