duanqiongchong0354 2015-05-19 20:59
浏览 44
已采纳

PDO - PHP致命错误:在[关闭]中的非对象上调用成员函数execute()

I'm working on this small project and I can't move on. PDO is working perfectly in other queries, no problem there - I hope. I've checked the site and the previously asked questions did not help me

this is my code:

try { //Step 1
$stmt_dataliiParinte = $db->prepare('INSERT INTO parintei (numeParinte, prenumeParinte, adresaParinte, localitateParinte, codpostalParinte, telefonParinte, mobilParinte, emailParinte, profesiaParinte, locmuncaParinte) VALUES (:numeParinte, :prenumeParinte, :adresaParinte, :localitateParinte, :codpostalParinte, :telefonParinte, :mobilParinte, :emailParinte, :profesiaParinte, :locmuncaParinte) ON DUPLICATE KEY UPDATE emailParinte=VALUES(:emailParinte)');
print_r($stmt_dataliiParinte);
$stmt_detaliiParinte->execute(array(
    ':numeParinte' => $numeParinte,
    ':prenumeParinte' => $prenumeParinte,
    ':adresaParinte' => $adresaParinte,
    ':localitateParinte' => $localitateParinte,
    ':codpostalParinte' => $codpostalParinte,
    ':telefonParinte' => $phoneNumber,
    ':mobilParinte' => $phoneNumber2,
    ':emailParinte' => $emailParinte,
    ':profesiaParinte' => $profesiaParinte,
    ':locmuncaParinte' => $locmuncaParinte
));
$parinteID = $db->lastInsertId();
} catch(PDOException $e) {
    $e->getMessage();
}

this is the print_r($stmt_dataliiParinte):

PDOStatement Object ( [queryString] => INSERT INTO parintei (numeParinte, prenumeParinte, adresaParinte, localitateParinte, codpostalParinte, telefonParinte, mobilParinte, emailParinte, profesiaParinte, locmuncaParinte) VALUES (:numeParinte, :prenumeParinte, :adresaParinte, :localitateParinte, :codpostalParinte, :telefonParinte, :mobilParinte, :emailParinte, :profesiaParinte, :locmuncaParinte) ON DUPLICATE KEY UPDATE emailParinte=VALUES(:emailParinte) )

so by the looks it's a PDOStatement object

I also tried to see if I have some variable error in the array so I also did an print_r on the execute array:

Array ( [:numeParinte] => dasda [:prenumeParinte] => dasdas [:adresaParinte] => dasdasd [:localitateParinte] => asdas [:codpostalParinte] => 23232 [:telefonParinte] => 1231231231231 [:mobilParinte] => 123123123123123 [:emailParinte] => x@x.com [:profesiaParinte] => asd [:locmuncaParinte] => dasdasdasd )

The names of the columns I've checked and double checked. I also tried removing the ON DUPLICATE KEY UPDATE, but with the same effect.

As I said before other queries work perfectly (example):

$stmt = $db->prepare('INSERT INTO tabere (dentabara,locatie,datastart,dataend,desctabara,pageID,tip,pret) VALUES (:dentabara, :locatie, :datastart, :dataend, :desctabara, :pageID, :tip, :pret)') ;
                            $stmt->execute(array(
                                ':dentabara' => $dentabara,
                                ':locatie' => $locatie,
                                ':datastart' => $datastart,
                                ':dataend' => $dataend,
                                ':desctabara' => $desctabara,
                                ':pageID' => $paginaTabara,
                                ':tip' => $tip,
                                ':pret' => $pret
                            ));
  • 写回答

1条回答 默认 最新

  • dsjuimtq920056 2015-05-19 21:03
    关注

    Spot the difference:

    $stmt_dataliiParinte = $db->prepare(' ... snip ...');
           ^
    $stmt_detaliiParinte->execute(array( ... snip ...));
           ^
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?