猿问

Fatal error,在使用fetchAll() 时报错,这是什么情况?

Fatal error: Call to a member function fetchAll() on boolean in C:\xampp\htdocs\pdo\pdoDome.php on line 50是什么原因??
源代码
//1.连接数据库
try{
$pdo = new PDO("mysql:host=localhost;dbname = test;","root","");
}catch (PDOException $e){
die("数据库连接失败".$e->getMessage());
}
print_r($pdo);

//2.执行query(查询)返回一个预处理对象
$sql = "select * from users";
$stmt = $pdo->query($sql);
$list = $stmt->fetchAll(PDO::FETCH_ASSOC);//解析数据
print_r($list);

森栏
浏览 157回答 1
1回答

海绵宝宝撒

SqlConnection con = new SqlConnectioncon.Open();string sqlstr = "sql语句";SqlDataAdapter da = new SqlDataAdapter(sqlstr, con);DataSet ds= new DataSet();da.Fill(ds);dataGridView1.DataSource = ds.Tables[0];con.Close();
随时随地看视频慕课网APP
我要回答