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