最近在使用laravel。
想批量插入近千条数据,知道直接写sql是可以批量插入的。
另外框架orm eloquent 提供了一个create方法:
/** * save a new model and return the instance. * * @param array $attributes * @return \illuminate\database\eloquent\model|static */ public static function create(array $attributes) { $model = new static($attributes); $model->save(); return $model; }
此方法可以很方便的插入数据,但是不能批量插入。
基于性能考虑吗,也不想写sql,请问eloquent 有针对这种情况的方法么?
回复内容: 最近在使用laravel。
想批量插入近千条数据,知道直接写sql是可以批量插入的。
另外框架orm eloquent 提供了一个create方法:
/** * save a new model and return the instance. * * @param array $attributes * @return \illuminate\database\eloquent\model|static */ public static function create(array $attributes) { $model = new static($attributes); $model->save(); return $model; }
此方法可以很方便的插入数据,但是不能批量插入。
基于性能考虑吗,也不想写sql,请问eloquent 有针对这种情况的方法么?
db::table('users')->insert(array( array('email' => 'taylor@example.com', 'votes' => 0), array('email' => 'dayle@example.com', 'votes' => 0),));
详情