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 有没有能解决微信公众号,只能实时拍照,没有选择相册上传功能,我不懂任何技术,,有没有给我发个软件就能搞定的方法
  • ¥15 Pythontxt文本可视化
  • ¥15 如何基于Ryu环境下使用scapy包进行数据包构造
  • ¥15 springboot国际化
  • ¥15 搭建QEMU环境运行OP-TEE出现错误
  • ¥15 Minifilter文件保护
  • ¥15 有限元软件终止时间超过设定值
  • ¥15 onvif框架引用一直报错
  • ¥50 C#和C++混合编程,使用CLR托管,报错System.Runtime.InteropServices.SEHException
  • ¥30 .NET使用sqlite发布后报错