Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从MySQL PDO查询结果创建数组_Php_Mysql_Arrays_Pdo - Fatal编程技术网

Php 从MySQL PDO查询结果创建数组

Php 从MySQL PDO查询结果创建数组,php,mysql,arrays,pdo,Php,Mysql,Arrays,Pdo,我有“用户”表: 这是我在pdo中使用的查询: $qry = "SELECT * FROM users"; 我想要的是将mysql pdo查询的结果存储在如下数组变量中: $result = array( array("id"=>1, "email"=>"asd@asd.as". "birthday"=>"02/03/1989", "city"=>"NY"), array("id"=>2, "email"=>"a

我有“用户”表:


这是我在pdo中使用的查询:

$qry = "SELECT * FROM users";
我想要的是将mysql pdo查询的结果存储在如下数组变量中:

$result = array(
   array("id"=>1,
    "email"=>"asd@asd.as".
    "birthday"=>"02/03/1989",
    "city"=>"NY"),
   array("id"=>2,
    "email"=>"asq@avt.al".
    "birthday"=>"06/01/1990",
    "city"=>"LA")
);
如何在php中将所有结果插入到这样的数组中?

您可以使用:

$result = array(
   array("id"=>1,
    "email"=>"asd@asd.as".
    "birthday"=>"02/03/1989",
    "city"=>"NY"),
   array("id"=>2,
    "email"=>"asq@avt.al".
    "birthday"=>"06/01/1990",
    "city"=>"LA")
);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
          ^^^^^ or whatever you use