I’m not able to get this example to work. Here is my code for totalfilms-function.inc.php where titles = the name of a table in my db:
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
function totalFilms()
{
try {
$result = $GLOBALS['pdo']->query('SELECT COUNT(*) FROM titles');
}
catch (PDOException $e)
{
$error = 'Database error counting films!';
include 'error.html.php';
exit();
}
$row = $result->fetch();
return $row[0];
}
The only other file I have in the totalfilms directory is error.html.php. When I load up the directory this is what I get:
It seems I need another file to display the result of the totalfilms function but I’m not sure how to write it.