Batch insert into mysql by RedBean

人走茶凉 提交于 2019-12-11 12:47:32

问题


How to run following sql by RedBean?

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

Should I use loop or RedBean support batch insert?


回答1:


Creator of RedBeanPHP here.

This is not supported by RedBeanPHP. You will have to use plain old SQL for this.




回答2:


What about sample logic?:

    $list = array(1, 2, 3, 4, 5, 6, 7, 8, 9);

    $beans = R::dispense('table', count($list));

    for($i=0; $i<count($list)/3; $i++)
    {
        $beans[$i]->a = $list[$i*3+1];
        $beans[$i]->b = $list[$i*3+2];
        $beans[$i]->c = $list[$i*3+3];
    }

    R::storeAll($beans);


来源:https://stackoverflow.com/questions/18416321/batch-insert-into-mysql-by-redbean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!