最近在使用laravel。
想批量插入近千条数据,知道直接写sql是可以批量插入的。
立即学习“PHP免费学习笔记(深入)”;
另外框架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是可以批量插入的。
立即学习“PHP免费学习笔记(深入)”;
另外框架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),
));
详情
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号