I am stumped, I changed hosts and I am now getting "Call to a member function prepare() on a non-object" on a script that has been working for months on the old server. I have read around here and tried several things I found but nothing seems to make it work again.
I am new at this so speak slowly and clearly please. ;)
$dbh = connect_db();
$sql = 'SELECT count(*) FROM ppipn WHERE txn_id = :txn_id';
$result = $dbh->prepare($sql);
$result->execute(array(':txn_id' => $txn_id));
$number_of_rows = $result->fetchColumn();
if ($number_of_rows>0){
die();
}
The function:
function connect_db()
{
$DbHost = 'localhost';
$DbName = '***n';
$DbUser = '***';
$DbPass = '***';
$table;
try
{
$connection = new PDO('mysql:host='.$DbHost.';dbname='.$DbName, $DbUser, $DbPass);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connection->setAttribute(PDO::ATTR_PERSISTENT, true);
}
catch (PDOException $e)
{
// Proccess error
echo 'Cannot connect to database: ' . $e->getMessage();
}
return $connection;
}