致命错误:在第 11 行的 /home/content/69/9179269/html/test/json-events.php 中的非对象上调用成员函数 fetchAll()
$result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
什么会导致这个错误?
`$username = "user";
$password = "psword";
$dbh = new PDO("mysql:localhost;dbname=databasename", $username, $password);
$sql = "SELECT `id`, `title`, `time`, `start`, `end`, `url`, `backgroundColor`, `textColor`, `borderColor`, `description`
FROM calender WHERE length(column) > 0";`
foreach ($result as $row){
$return[]=array('id'=>$row['id'],
'title'=>$row['title'],
'start'=>$row['start'].' '.$row['time'],
'end'=>$row['end'],
'url'=>$row['url'],
'backgroundColor'=>$row['backgroundColor'],
'textColor'=>$row['textColor'],
'borderColor'=>$row['borderColor'],
'description'=>$row['description'],
"allDay" => false);
}
$dbh = null;
header('Content-type: application/json');
echo json_encode($return);