php - 组合字母数字时如何选择真值?
问题描述
mysql:(customer_number = int
无法更改)
$query = "SELECT * FROM clients WHERE customer_number= '123F'"
结果应该是空的。
该查询的结果不正确,因为 MySQL 忽略了任何字母字符,这些字母字符构成具有整数数据类型的值的一部分,例如。'F'
解决方案
You can check if the value provided is strictly integer.
$query = "SELECT * FROM clients WHERE customer_number= '123F'
AND '123F' REGEXP '^-?[0-9]+$'";
AND
needs both conditions compulsorily.
So, even if MySQL ignores F
from 123F
and treats it as 123
, second condition will return FALSE
and 123F
will fail regular expression of strictly integer condition.
This will have following results:
123
-> pass
123F
-> fail
推荐阅读
- ruby-on-rails - Ruby on rails:如何设置内联字符串翻译(无需更改 config/locales/*.yml)
- python - 如何使用 Haar 级联进行人脸检测和卡尔曼滤波器进行跟踪?
- laravel - 如何在 laravel 项目中集成 mailjet?
- c# - 使用 ExcelFile 保存文件失败
- javascript - 带有 .mp4 的 Math.random javascript
- c# - 如何使用类型运行 LINQ 查询
- browser-cache - Vue CLI3:无法更改网站图标
- javascript - VSCode TypeScript 列表字段名称
- angular - 在内部/使用ngrx效果打开角度materialdDialogs
- c++ - MinGW 将类中对象的第二次声明视为构造函数