我想工作的代码,但出现错误:
$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")');
如何使第一个示例中的代码起作用?
答案 0 :(得分:2)
您需要将值作为数组传递。就像在其周围加上括号一样简单。
$add = DB::insert('insert into clients (name,user_id,subdomain) values (?, "3", "test")', [$test]);