SQL查询通过php脚本成功执行但不更新数据库

问题描述 投票:0回答:1

就像标题所说,当通过php脚本执行我的查询时,它运行成功,但没有更新数据库。

直接在 SSMS 中执行查询,它可以 100% 工作并更新记录。它曾经可以工作,但今天它停止工作了,我不知道是什么导致了这个问题。

数据库中的所有列都是 VARCHAR 值。 下面是查询和 PHP 执行块

try {
    odbc_exec(CONNECTION, $SQL_ORDERS_INSERT);
    echo "LOCAL ORDERS ADDED<br><br>";
    odbc_free_result($ORDER_ADD);
catch (\Throwable $th) {
    echo $th->getMessage();
}

SQL 查询字符串已添加到变量

$SQL_ORDERS_INSERT
:

IF NOT EXISTS (SELECT ORDER_NUMBER FROM dbo.ORDERS WHERE ORDER_NUMBER = 'ELD24-11-50') 
    INSERT INTO dbo.ORDERS (ORDER_NUMBER, TRANSACTION_TYPE, TRANSPORTER_CODE, SUPPLIER_CODE, SOURCE_CODE, CLIENT_CODE, 
    DESTINATION_CODE, ORDER_STATUS, ORDER_DATE, PRODUCT_CODE, TOTAL_WEIGHT, REMAINING, 
    COMMENT_DESCRIPTION_1, COMMENT_1, COMMENT_DESCRIPTION_2, COMMENT_2, COMMENT_DESCRIPTION_3, COMMENT_3, 
    REMAINING_TRUCKS, EMAIL_SENT, ORDER_SUCCESSOR, BARCODE_RECEIVING, SEAL_QUANTITY, SLIP_FIRST_WEIGH, TRUCKS_PER_DAY,
    NWP_SYNC) 
    VALUES ('ELD24-11-50', 'DISPATCHING', 'VRC', 'ELD', 'CHROME ', 'CHR', 
    'WB', 'ACTIVE', '2024-11-01 13:43', 'CHR001', '3100000', '-56400', 
    '', '', '', '', '', '', 
    '-1', '0', '', '0', '2', 'N/A', '999', '0') 
IF EXISTS (SELECT ORDER_NUMBER FROM dbo.ORDERS WHERE ORDER_NUMBER = 'ELD24-11-50') 
UPDATE dbo.ORDERS SET TRANSACTION_TYPE = 'DISPATCHING', 
                      TRANSPORTER_CODE = 'VRC', 
                         SUPPLIER_CODE = 'ELD', 
                           SOURCE_CODE = 'CHROME ', 
                           CLIENT_CODE = 'CHR', 
                      DESTINATION_CODE = 'WB', 
                          ORDER_STATUS = 'COMPLETE', 
                            ORDER_DATE = '2024-11-01 13:43', 
                          PRODUCT_CODE = 'CHR001', 
                          TOTAL_WEIGHT = '3100000', 
                             REMAINING = '-56400', 
                 COMMENT_DESCRIPTION_1 = '', 
                             COMMENT_1 = '',
                 COMMENT_DESCRIPTION_2 = '', 
                             COMMENT_2 = '', 
                COMMENT_DESCRIPTION_3 = '',
                            COMMENT_3 = '', 
                     REMAINING_TRUCKS = '-1', 
                           EMAIL_SENT = '0', 
                      ORDER_SUCCESSOR = '', 
                    BARCODE_RECEIVING = '0', 
                        SEAL_QUANTITY = '2', 
                     SLIP_FIRST_WEIGH = 'N/A', 
                       TRUCKS_PER_DAY = '999', 
                             NWP_SYNC = '1' 
WHERE ORDER_NUMBER = 'ELD24-11-50'

php sql sql-server ssms
1个回答
0
投票

$SQL_ORDERS_INSERT 太长。 PHP 仅支持 256 个字符的字符串集。

© www.soinside.com 2019 - 2024. All rights reserved.