如何使用RedBeanPhp批量插入? [英] How to bulk insert with RedBeanPhp?

查看:116
本文介绍了如何使用RedBeanPhp批量插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望得到一个示例,该示例说明如何在不循环每个实例的情况下在readbeanphp中批量插入新的"beans".

I was hoping for an example on how to bulk insert new "beans" in readbeanphp without looping over each instance.

它显示了一个在此处创建和保存bean的示例: http://redbeanphp.com/manual/create_a_bean

It shows an example creating and saving a beans here: http://redbeanphp.com/manual/create_a_bean

它提到了storeAll($ beans)方法,但是我不确定我应该如何格式化$ beans中的数据.

It makes mention of storeAll($beans) method, but I am unsure exactly how I am suppose to format the data in $beans.

我已尝试对此进行谷歌搜索,但找不到与批量插入内容相关的任何内容.也许我搜索了错误的字词.

I have tried googling for this and can not find anything related to bulk inserts. Maybe I have searched for the wrong terms.

我是这个ORM的新手,任何帮助将不胜感激,谢谢!

I am new to this ORM, any help with would appreciated, thanks!

推荐答案

您绝对是正确的.使用$bean=R::dispense('bean');或多个bean作为数组$beans=R::dispense('bean',5);

You are definitely right on track. Create a new bean using $bean=R::dispense('bean'); or multiple beans as an array $beans=R::dispense('bean',5);

然后,用数据填充bean:

Then you populate the beans with data:

$bean->title='Hello World!';
//or with an array
$beans[0]->title='Hello World!';
$beans[1]->title='Hello World! Bean 1';
//etc

然后存储bean:

R::store($bean);
//or
R::storeAll($beans);

如果据我所知有多个倍数,则所有Bean必须为相同类型,因此您可以执行以下操作:

All the beans must be the same type if you have multiples as far as I know, so you can do something like:

$beans=array();
$beans[]=R::dispense('bean');
$beans[]=R::dispense('bean');
$beans[0]->title='Hello World!';
$beans[1]->title='Hello World!1';
R::storeAll($beans);

我对此可能是错的.最主要的是,这都是典型的ORM,但如果需要使用redbean,它也支持常规SQL.希望有帮助!

I could be wrong about that though. The main thing is that this is all a typical ORM, but redbean also supports regular SQL if you need to use it. Hope that helps!

这篇关于如何使用RedBeanPhp批量插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆