在线生产环境中,Eloquent模型中的id周围的引号是必需的,但在本地主机上无法正常工作。
在线生产环境中,Eloquent模型中的id周围的引号是必需的,但在本地主机上无法正常工作。
我有一个查询,在我的生产环境安装中,在'where'方法中需要在"id"周围加上引号,否则返回没有结果。在我的本地安装中,正好相反。如果我使用引号,它就无法正常工作。
生产环境:
'invoices' => Auth::user()->invoices->where('paid', "0")
本地主机:
'invoices' => Auth::user()->invoices->where('paid', 0)
这真的很奇怪,我真的不想每次从github部署时都要去更改这个。这是常见的问题吗?我似乎找不到任何相关资料。
我将列出一些Laravel查询日志:
在带引号的整数的本地安装中(不起作用):
Array ( [0] => Array ( [query] => select * from `users` where `users`.`id` = ? limit 1 [bindings] => Array ( [0] => 1 ) [time] => 10.49 ) [1] => Array ( [query] => select * from `invoices` where `invoices`.`user_id` = ? and `invoices`.`user_id` is not null [bindings] => Array ( [0] => 1 ) [time] => 1.39 ) )
在不带引号的整数的本地安装中(起作用):
Array ( [0] => Array ( [query] => select * from `users` where `users`.`id` = ? limit 1 [bindings] => Array ( [0] => 1 ) [time] => 0.84 ) [1] => Array ( [query] => select * from `invoices` where `invoices`.`user_id` = ? and `invoices`.`user_id` is not null [bindings] => Array ( [0] => 1 ) [time] => 1.15 ) )
在不带引号的整数的生产安装中(不起作用):
Array ( [0] => Array ( [query] => select * from `users` where `users`.`id` = ? limit 1 [bindings] => Array ( [0] => 1 ) [time] => 2.3 ) [1] => Array ( [query] => select * from `invoices` where `invoices`.`user_id` = ? and `invoices`.`user_id` is not null [bindings] => Array ( [0] => 1 ) [time] => 0.67 ) )
在带引号的整数的生产安装中(起作用):
Array ( [0] => Array ( [query] => select * from `users` where `users`.`id` = ? limit 1 [bindings] => Array ( [0] => 1 ) [time] => 0.88 ) [1] => Array ( [query] => select * from `invoices` where `invoices`.`user_id` = ? and `invoices`.`user_id` is not null [bindings] => Array ( [0] => 1 ) [time] => 0.81 ) )
解决方案:
原来我在服务器上没有激活mysqlnd驱动程序。激活它解决了这个问题。