我应该禁用MySQL严格模式吗? [英] Should I disable MySQL strict mode?

查看:136
本文介绍了我应该禁用MySQL严格模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在一个启用了MySQL严格模式的网站上工作.一个人的用户代理字符串很长,该字符串已记录在我们的日志表中,很遗憾,该用户代理字符串超出了该列的限制,因此引发了警告.根本没有插入数据.

I have been working on a site that had MySQL strict mode enabled. One person had a long user agent string that was logged in our log table and unfortunately the user agent string exceeded the limit for the column and thus caused a warning. The data was not inserted at all.

为避免此类麻烦,我应该禁用MySQL严格模式还是应该自己提出一些建议(我正在使用PHP)?

To avoid such troubles, should I disable the MySQL strict mode or should I come up with something on my own (I'm using PHP)?

推荐答案

先验证数据,然后再将其插入数据库.如果字符串太大而不能容纳在表中,则说明列太窄,或者数据无效.您需要确定是否在存储它之前将其截断,进行一些错误报告或同时进行这两种操作.

Validate the data before inserting it into your database. If a string is too big to fit in your table, either your column is too narrow, or the data is invalid. You need to decide whether you truncate it before storing it, do some error reporting, or both.

不要关闭DBMS的安全功能,这是完全错误的事情.

Do not turn off the safety features of your DBMS, that's the completely wrong thing to do.

这篇关于我应该禁用MySQL严格模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆