Code: Select all
<?php
$dbh = new PDO('mysql:host=localhost;dbname=est', $user, $pass);
// meanwhile somewhere else in the code
$countSql = "SELECT COUNT(`id`) FROM `user_main` WHERE
`username` = ?";
$sth = $dbh->prepare($countSql);
?>Fatal error: Call to a member function prepare() on a non-object in...
My thinking is to check whether $dbh is an object, and based on that continue with the process, something like
Code: Select all
<?php
if (is_object($dbh)) {
// i can go on and interact with the database
}
?>Some more information that might be relevant - i'm creating an instance of a PDO object inside the construct of a class which i then set as class property so most of my checking would be done inside other class methods.