比如我不希望 username 是纯数字的,如果程序 insert 的数据,username 是纯数字的,就返回 mysql 数据格式错误,有这种功能吗?
PHP中文网2017-04-17 14:49:14
Achieved through stored procedures or triggers, but this logic is best controlled by the code layer
天蓬老师2017-04-17 14:49:14
Let’s talk about the conclusion first: I agree with LS’s point of view. Generally, verification is written in the program, and the database only does basic constraints such as unique
If you really want to do it in the database, you will usually write trigger
Then there seems to be add constraint check, but even if mysql supports this, it will not check before storage (all engines)
http://stackoverflow.com/questions/16005283/is-it-possible-to-enforce-data-checking-in-mysql-using-regular-expression
PHPz2017-04-17 14:49:14
Program logic problems should not be left to the database to handle, or it should be used as the last line of verification defense.
高洛峰2017-04-17 14:49:14
This kind of basic verification is also done in the database. Doesn’t this just put more pressure on the database? Everyone is reducing the burden on it