Laravel错误参数1传递给Illuminate \ Database \ Connection :: prepareBindings()必须是数组类型,给定字符串,在

时间:2018-12-31 14:31:12

标签: php laravel laravel-5.2

我想工作的代码,但出现错误:

$test= 'test1';
$add = DB::insert('insert into clients (name,user_id,subdomain) values (?, "3", "test")', $test);

错误:

Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, string given, called in C:\xampp\htdocs\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 454

但是此代码有效:

$add = DB::insert('insert into clients (name,user_id,subdomain) values ("name", "3", "test")');

如何使第一个示例中的代码起作用?

1 个答案:

答案 0 :(得分:2)

您需要将值作为数组传递。就像在其周围加上括号一样简单。

$add = DB::insert('insert into clients (name,user_id,subdomain) values (?, "3", "test")', [$test]);