PDO :: FETCH_ASSOC什么是PDO :: FETCH_ARRAY? [英] PDO::FETCH_ASSOC What is about PDO::FETCH_ARRAY?
本文介绍了PDO :: FETCH_ASSOC什么是PDO :: FETCH_ARRAY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<?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);
?>
上面的示例将获取结果集中的所有其余行,并输出类似于:
The above example will fetch all of the remaining rows in the result set and output something similar to:
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
返回的结果,如下所示:
Is there any option to get a result like the one my_sql_fetch_array
returns, which looks like this:
Array
(
[0] => Array
(
[0] => pear
[1] => green
)
[1] => Array
(
[0] => watermelon
[1] => pink
)
)
推荐答案
来自 http://php.net/manual/en/pdostatement.fetch.php
$result = $sth->fetchAll(PDO::FETCH_NUM);
这篇关于PDO :: FETCH_ASSOC什么是PDO :: FETCH_ARRAY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文