[英]How to pass array in laravel where condition?
$table='user';
$conditions=array(
'uname' => 'test',
'pwd' => '123'); //uname and pwd are the column names
DB::table($table)->where($conditions)->get();
在执行上面的代码时显示以下错误
ErrorException
strtolower() expects parameter 1 to be string, array given
谁能帮助我。
我不知道您正在使用哪个类,但是您的php编译器说您通过了数组而不是字符串,所以也许尝试以字符串格式传递条件:
$conditions = "uname='test'&pwd='123'";
更新
正如您在docs( http://laravel.com/docs/queries#selects )中所看到的那样,您只能将字符串传递给where
方法,因此您必须这样做:
$select = DB::table($table);
foreach($conditions as $column=>$value){
$select->where($column,'=',$value);
}
$result = $select->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.