简体   繁体   English

PDO-> execute()语句将不起作用,并且在语法上正确

[英]PDO->execute() statement won't work and is syntactically correct

I can't understand why this PDO statements won't save anything into the database: 我不明白为什么这个PDO语句不会将任何内容保存到数据库中:

          //guardamos en base           
          $conectar2 = new PDO('mysql:host='.HOST.'; dbname='.DATABASE.'; charset=utf8', USER, PASS); 
          $conectar2->beginTransaction();
          $agregarData = $conectar2->prepare("
              UPDATE mensajes
              SET estadoMensaje = ?, 
                  datosMensaje = ?
              WHERE mensajeID = ?;
            ");
          $agregarData->bindParam(1, $estadoMensaje);
          $agregarData->bindParam(2, $data);
          $agregarData->bindParam(3, $mensajeID);             
          $agregarData->execute();

          echo '<br>Mensaje actualizado.';

My error log won't say anything. 我的错误日志什么也没说。 Anything out of place that I could have missed? 有什么地方我想念的吗?

I've tried the sql statement into mysql by hand and it works. 我已经尝试过将sql语句手动插入mysql,并且可以正常工作。

I've echoed the variables and they are not empty (they are all strings). 我已经回显了变量,它们不是空的(它们都是字符串)。

The connection does work. 连接确实起作用。

What am I missing? 我想念什么?

You began a transaction but forgot to commit it. 您开始了一笔交易,但忘记提交了。

Adding: 新增:

$conectar2->commit();

after issuing your queries will fix the problem. 发出查询后即可解决问题。

You might consider removing the transaction altogether if there are no other queries being issued. 如果没有发出其他查询,则可以考虑完全删除事务。

"Anything out of place that I could have missed?" “有什么地方我想念的吗?”

Yes. 是。

$conectar2->beginTransaction();

This part needs to be removed. 此部分需要删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM