我这样写也可以返回关联数组
<?php
header('content-type:text/html;charset=utf-8');
error_reporting(E_ALL^E_NOTICE);
try {
$pdo=new PDO('mysql:host=localhost;dbname=imooc', 'root', 'root');
$sql='SELECT * FROM user';
$stmt=$pdo->prepare($sql);
$res=$stmt->execute();
if($res){
while($row=$stmt->fetch(MYSQL_ASSOC)){
print_r($row);
echo'<br/>';
}
}
}catch (PDOException $e){
echo $e->getMessage();
}