我最近将我的服务器从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
尝试执行print_r
$ query和$ data这是它返回的内容:
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正在以严格模式运行。
好的,这里发布的解决方案:#1366 - Incorrect integer value:MYsql有帮助,但我觉得这是一种解决方法,而不是修复,仍然希望能够正确修复它。
谢谢。
答案 0 :(得分:0)
好的,我发现了问题。
阅读:https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_error_for_division_by_zero并查看下表,我已按以下方式调整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 |
+---------------------------------+----------------------------------------------------------------------------------+---------------------------+