dtpn60029 2014-08-27 15:45
浏览 57
已采纳

PHP创建过程

I try to create a stored procedure through php mysqli. I create another stored procedures and I didn´t have problems. This code:

$link = new mysqli("localhost", "root", "", "Question");
$link -> multi_query("DROP PROCEDURE IF EXISTS FacturaTerminarFactura;
    CREATE DEFINER=`root`@`%` PROCEDURE `FacturaTerminarFactura`(IN 
    id_factura INT(40), Total_factura DOUBLE, Total_IVA DOUBLE)
    BEGIN
    UPDATE `tb_factura`
        SET
        `tb_factura`.`intId_factura_resolucion_dian` = (SELECT
            MAX(`tb_resolucion_dian`.`intFactura_Actual`) FROM `tb_resolucion_dian`
            WHERE `tb_resolucion_dian`.`intEstado` = 1 LIMIT 1),
            `tb_factura`.`dblTotal_factura` = Total_factura,
            `tb_factura`.`dblIva` = Total_IVA
        WHERE `tb_factura`.`intid_factura` = id_factura;
   UPDATE `tb_resolucion_dian`
        SET `tb_resolucion_dian`.`intFactura_Actual` = 
            tb_resolucion_dian`.`intFactura_Actual` + 1
        WHERE `tb_resolucion_dian`.`intEstado` = 1;
   SELECT `tb_factura`.`intId_factura_resolucion_dian` AS ID
       FROM `tb_factura`
       WHERE `tb_factura`.`intid_factura` = id_factura;
END;");
$log  = "";
if ($mysqli -> warning_count) {
     if ($result = $link -> query("SHOW WARNINGS;")) {
         $row = $result -> fetch_row();
         $log .= $row[0]."-".$row[1]."-".$row[2]."
";
         $result -> close();
     }
}

This is the error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '`.`intFactura_Actual` 1 WHERE 
`tb_resolucion_dian`.`intEstado` = 1; ' at line 14

I see that the '+' is the problem, but I don't know how I can resolve.

Thanks and excuse me for my English.

  • 写回答

2条回答 默认 最新

  • dongshen9058 2014-08-27 15:57
    关注

    You have a typo Here:

    tb_resolucion_dian`.`intFactura_Actual` + 1
    

    You're missing the backtick before tb_resolucion_dian

    Also, according to mysql docs for UPDATE you don't need to name the table name in the SET clause. The example given was UPDATE t1 SET col1 = col1 + 1; where you have UPDATE t1 SET t1.col1 = t1.col1 + 1, which might also cause issues.

    An alternative to UPDATE is INSERT INTO ... SELECT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数