I have the following sql code:
$statement = "`maildb`";
$query = "SELECT COUNT(*) as `num` FROM {$statement}";
$row = mysql_fetch_array(mysql_query($query));
I am trying to transform to PDO... I have tried the following:
$statement = "`maildb`";
$query = $db->prepare("SELECT COUNT(*) as `num` FROM {$statement}");
$query->execute();
$row = $query->fetchAll(PDO::FETCH_ASSOC);
That results in: Fatal error: Call to a member function prepare() on a non-object in function.php on line 8.
I have also tried this before, which should do the same:
$query = $db->prepare("SELECT * FROM maildb");
$query->execute();
$row = $query->fetchAll(PDO::FETCH_ASSOC);
$num = count($row);
Any help?
Thank you!!