My website is currently in French, English and Dutch. French is the main language and the only one working up to now.
My jquery script makes an ajax call to a php page.
The response I got is this one : Fatal error: Call to a member function prepare() on a non-object in
How can I get rid of this error ? On the french version it works perfectly ! The 3 languages uses the same php script.
fermetureEtablissement = [] ;
$.ajax({
type: "POST",
url: "./admin/datesajax.php",
data: ({idproduit: 'tous'}),
cache: false,
dataType: "json",
async: false,
success: function(data) {
fermetureEtablissement = data;
}
});
Do you have any idea how to fix this problem ?
You can see the not working page here :
- Click on "book" on this page : http://www.velo-montagne.com/en/hotel/au-colombier-de-luxe-room
- Then check the ajax call and the response. It shows the error.
You can see the working page here :
- Click on "reserver" on this page : http://www.velo-montagne.com/hotel/chambre-au-colombier-de-luxe
- Then check the ajax call and the response. It works great !
Example of dateajax.php :
if ($_POST['idproduit'] == 1 or $_POST['idproduit'] == 4 or $_POST['idproduit'] == 5 or $_POST['idproduit'] == 'tous' or $_POST['idproduit'] == 'ouverturesexceptionnelles' ){
$sth1 = $dbh->prepare("SELECT datesbloquees FROM vm_datesbloquees WHERE idproduit = :idproduit" );
$sth1->execute(array(':idproduit' => $_POST['idproduit']));
$result = $sth1->fetchAll();
$tableaudatesbloquees = explode(",", $result[0]['datesbloquees']);
//print_r($tableaudatesbloquees);
}
function dbConnect(){
global $dbh;
$dbInfo['database_target'] = "xxx";
$dbInfo['database_name'] = "xxx";
$dbInfo['username'] = "xxx";
$dbInfo['password'] = "xxx";
$dbConnString = "mysql:host=" . $dbInfo['database_target'] . "; dbname=" . $dbInfo['database_name'];
$dbh = new PDO($dbConnString, $dbInfo['username'], $dbInfo['password'],array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}