我有一个来自 MariaDB 视图的非常简单的查询:
SELECT c.amount, c.discount
FROM factors_view as c
WHERE c.factor_id = 358
当我在 HeidiSQL 中运行这个查询时,我得到了这个结果:amount = 16000, discount = 1200
但是在 Laravel 5.7 原始查询中
$result = \DB::select("
SELECT c.amount,c.discount
FROM factors_view as c
WHERE c.factor_id = 358"
);
结果:amount = 16000, discount = 0当我将参数放在引号之间时:
$result = \DB::select("
SELECT c.amount,c.discount
FROM factors_view as c
WHERE c.factor_id = '358'"
);
结果:amount = 16000, discount = 1200
c.factor_id 的类型是int(10) unsigned。
这对我来说很奇怪;因为区别在于查询条件,而不是选择!
输出是在特定列上具有零值的同一行!
有谁知道发生了什么事?
这是我对这两个查询的查询日志:
1)
query:"select `c`.`amount`, `c`.`discount` from `factors_view` as `c` where `c`.`factor_id` = ?"
bindings:[0:358]
2)
query:"select `c`.`amount`, `c`.`discount` from `factors_view` as `c` where `c`.`factor_id` = ?"
bindings:[0:"358"]
千万里不及你
喵喵时光机