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条)

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件