I've looked everywhere for an answer to this so hopefully one of you wise people can help me out.
Since changing web servers in the last couple of weeks none of my database driven code seems to be working. I've identified a work around but I'm not sure why the problem is occurring.
Here's a simple example to explain the problem:
the db.inc file:
Code: Select all
try {
$db = new PDO('mysql:host=localhost;dbname=wedding', $user, $pass);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
Code: Select all
include 'db.inc';
// first time accessing the database
$sql = 'SELECT COUNT(*) FROM users WHERE guest_email = ?;';
$pds = $db->prepare($sql);
$pds->execute(array($email));
if($pds->fetchColumn() == 1) {
// second time accessing the database
$sql = 'SELECT * FROM users WHERE guest_email = ?;';
$pds = $db->prepare($sql);
$pds->execute(array($email));
}
The only way to get this to work on the new web server, however, is to re include the db.inc file every time i access the database.
See below:
Code: Select all
include 'db.inc';
// first time accessing the database
$sql = 'SELECT COUNT(*) FROM users WHERE guest_email = ?;';
$pds = $db->prepare($sql);
$pds->execute(array($email));
if($pds->fetchColumn() == 1) {
// now i need to re-include the db connection before i can access again
include 'db.inc';
// second time accessing the database
$sql = 'SELECT * FROM users WHERE guest_email = ?;';
$pds = $db->prepare($sql);
$pds->execute(array($email));
}
Web Server is running php v5.1.6
Test environment is running php v5.3.0
Cheers,
fando