Reputation: 704
Fatal error: Call to a member function fetchAll() on a non-object in /home/content/69/9179269/html/test/json-events.php on line 11
$result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
what would cause this error?
`$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);
Upvotes: 0
Views: 141
Reputation: 12872
query() is not returning a pdo statement. That means your query probably failed. Check your sql statement and error message.
Turn on error reporting with
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
so you can see your error messages.
Upvotes: 1