-2

Hey I am following a turtorial on Youtube to set up a basic CMS with php and MySQL.

Now I got a fatal error

"Call to a member function fetchAll() on boolean"

even tho' I have been writing the same as in the turtorial. The turtorial I am following is https://www.youtube.com/watch?v=dQ4_eJvnEBc

Here is the code where the fatal error is (list.php):

<?php
require '../app/start.php';
$pages = $db->query("
    SELECT id, label, tite, slug
    FROM pages
    ORDER BY created DESC
")->fetchAll(PDO::FETCH_ASSOC);
var_dump($pages);

The connection to the database is this code (start.php):

<?php
ini_set('display_errors', 'on');
define('APP_ROOT', __DIR__);
define('VIEW_ROOT', APP_ROOT . '/views');
define('BASE_URL', 'http://localhost/myPHP');
$db = new PDO('mysql:host=127.0.0.1;dbname=mycms', 'root', '');
require 'functions.php';

Does anyone know what is causing the fatal error?

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Kelsner
  • 59
  • 2
  • 9
  • 1
    http://php.net/manual/en/pdo.error-handling.php - http://php.net/manual/en/function.error-reporting.php - might just be a typo for `tite` which should probably be `title`. *who knows*. – Funk Forty Niner Feb 15 '16 at 14:50
  • 1
    Your query is failing for some reason and returning a BOOLEAN false instead of data. Proper error checking will reveal the actual issue. – Jay Blanchard Feb 15 '16 at 14:56

1 Answers1

0

Your query() call returns false as it's failed. That's why fetchAll can't be executed.

Debug your query! (I think it's a typo error and tite should be title)

Kristian Vitozev
  • 5,791
  • 6
  • 36
  • 56