簡體   English   中英

服務器更新后,MySQL insert null 不起作用

[英]MySQL insert null doesn't work after server update

我最近將我的服務器從 14.04 更新到 16.04(即 Ubuntu),通過這樣做,我還將 MySQL 和 PHP 服務器更新為:

服務器版本:5.7.19-0ubuntu0.16.04.1 - (Ubuntu)

PHP 版本:7.0.22-0ubuntu0.16.04.1

因為我的很多應用程序開始行為不端,這都與 NULL 有關。

看一個例子,這里是 PHP 代碼:

$stmt=$db->prepare($query);
$stmt=$db->execute($data);

但這會導致:PHP 消息:PHP 致命錯誤:

Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'NULL' for column 'id' at row 1

嘗試執行 $query 和 $data 的print_r這是它返回的內容:

insert into `company` (`id`,`Name`,`customerid`,`named_person`,`email`,`contact_no`,`payment_term`,`billing_contact`,`billing_email`,`billing_add1`,`billing_add2`,`billing_postcode`,`docketmail`,`livefeed`,`auto_populate`,`risk`,`question`,`livefeed_pass`,`livefeed_user`,`owner`) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) on duplicate key update`Name`=?,`customerid`=?,`named_person`=?,`email`=?,`contact_no`=?,`payment_term`=?,`billing_contact`=?,`billing_email`=?,`billing_add1`=?,`billing_add2`=?,`billing_postcode`=?,`docketmail`=?,`livefeed`=?,`auto_populate`=?,`risk`=?,`question`=?,`livefeed_pass`=?,`livefeed_user`=?

Array
(
    [0] => NULL
    [1] => sdasdasd
    [2] => 0
    [3] => sdasdasd
    [4] => asdasdas
    [5] => sdasdasd
    [6] => 14
    [7] => dadasdsad
    [8] => asdsadasd
    [9] => dasdasdas
    [10] => dasdasdsad
    [11] => dasdasdas
    [12] => 
    [13] => 0
    [14] => 1
    [15] => 0
    [16] => 0
    [17] => 
    [18] => 
    [19] => 1
    [20] => sdasdasd
    [21] => 0
    [22] => sdasdasd
    [23] => asdasdas
    [24] => sdasdasd
    [25] => 14
    [26] => dadasdsad
    [27] => asdsadasd
    [28] => dasdasdas
    [29] => dasdasdsad
    [30] => dasdasdas
    [31] => 
    [32] => 0
    [33] => 1
    [34] => 0
    [35] => 0
    [36] => 
    [37] => 
)

這在更新服務器之前有效。

innodb 在關閉的嚴格模式下運行。

更新

此處發布的解決方案有所幫助,但我覺得這是一種解決方法而不是修復方法,並且仍然希望正確修復它。

好的,我發現了問題。

閱讀: https : my.cnf表,我對my.cnf做了如下調整:

 sql_mode=ERROR_FOR_DIVISION_BY_ZERO

現在它按我的預期工作,不知道為什么它首先出錯。

+---------------------------------+----------------------------------------------------------------------------------+---------------------------+
| Desired Behavior                | MySQL 5.7.x Versions Except 5.7.4 Through 5.7.7                                  | MySQL 5.7.4 Through 5.7.7 |
+---------------------------------+----------------------------------------------------------------------------------+---------------------------+
| insert NULL, produce no warning | ERROR_FOR_DIVISION_BY_ZERO not enabled                                           | strict mode not enabled   |
| insert NULL, produce warning    | ERROR_FOR_DIVISION_BY_ZERO, or ERROR_FOR_DIVISION_BY_ZERO + strict mode + IGNORE | strict mode + IGNORE      |
| error                           | ERROR_FOR_DIVISION_BY_ZERO + strict mode                                         | strict mode               |
+---------------------------------+----------------------------------------------------------------------------------+---------------------------+

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM