$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'";
更新
正如您在文档( http://laravel.com/docs/queries#selects )中看到的,您只能将字符串传递给 where
方法,因此您必须这样做:
$select = DB::table($table);
foreach($conditions as $column=>$value){
$select->where($column,'=',$value);
}
$result = $select->get();
关于php - 如何在 laravel where 条件中传递数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435985/