php – 有没有办法检测mysql中的溢出?

经过一段时间试图杀死这个bug,我直接测试了SQL查询

UPDATE noticias SET
    data_destaque_ini='2013-12-03', data_destaque_fim='',
    fotoDestaque_x=-3, fotoDestaque_y=-102,
    fotoDestaque_escala=154, destacar=1
WHERE idNoticia=3

但fotoDestaque_escala保持与以前相同的值:127.嗯,这是一个“圆”数,对吗?因此,即使没有任何sql错误消息,我打开了结构,就是这样:列设置为tinyint(-127到127),并将其更改为SMALLINT解决了问题.

但是考虑到未来,我对MysqL的这种行为感到震惊:我为这个专栏传递了太大的价值,MysqL保存了可能的东西,削减了其余部分,并且没有说出任何关于 – 客户端仍处于黑暗状态!

那么,有没有办法以某种方式配置或检测溢出?如果没有,我正在考虑在我的库中进行PHP级别测试…

解决方法:

直接取自MysqL文档中的11.2.6 Out-of-Range and Overflow Handling

When MysqL stores a value in a numeric column that is outside the permissible range of the column data type, the result depends on the sql mode in effect at the time:

  • If strict sql mode is enabled, MysqL rejects the out-of-range value with an error, and the insert fails, in accordance with the sql standard.
  • If no restrictive modes are enabled, MysqL clips the value to the appropriate endpoint of the range and stores the resulting value instead.

因此,如果您想要一个错误,您需要将MysqL置于严格的sql模式.如何更改模式在5.1.7 Server SQL Modes中描述.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...