生成SQL语句

User::whereIn('id',[1,2,3])->lists('id');

这里怎么样生成SQL语句(id 1,2,3只是例子),方便我下一步

insert a (id) select id from user where id in (1,2,3);

我主要想用这个批量增加到数据库

var_dump(Model::where('foo', '=', 'bar')->toSql())

在后头加->toSql()就可以输出SQL 语句

ty0716
DB::getQueryLog();

建议装个debug

dope2008

楼上的我知道,我不是想要这个东西。。

linyu0423

var_dump(Model::where(‘foo’, ‘=’, ‘bar’)->toSql())

在后头加->toSql()就可以输出SQL 语句

dope2008

输出的是
"select * from users where foo = ?"
?号不能是bar?

ronghuaxueleng

query=Model::where(foo,=,bar);query = Model::where('foo', '=', 'bar'); sql = str_replace("?", “’%s’”, query>toSql())vsprintf(query->toSql()) vsprintf(sql, $query->getBindings())