duanhong1985 2013-12-26 18:47
浏览 60

PHP - Ajax调用 - <b>致命错误</ b>:在非对象上调用成员函数prepare()

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 :

  1. Click on "book" on this page : http://www.velo-montagne.com/en/hotel/au-colombier-de-luxe-room
  2. Then check the ajax call and the response. It shows the error.

You can see the working page here :

  1. Click on "reserver" on this page : http://www.velo-montagne.com/hotel/chambre-au-colombier-de-luxe
  2. 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);

}
  • 写回答

1条回答 默认 最新

  • douzhangbao2187 2013-12-26 19:16
    关注

    The variable $dbh does not contain the database object

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法