dsfsdfsdfsdf6455 2013-04-20 14:32
浏览 37
已采纳

在一个doctrine native insert()命令中插入多个关联数组

Is there any way, I can insert multiple associative array in database table with doctrine's native sql query execution support? Currently, I can see to insert only a single row/associative array. code:

$connection = $em->getConnection();
$connection->insert('un_table_name', $associative_data_array);

My goal is to insert mutiple row in single statement so that they are inserted in single transaction.

Just to clarify, I am working on a migration task where data will be processed and transffered from old schema to new schema. but as entities are in only new schema structure, I can connect both db with ORM style. This is why I am following the native query support. also as bulk data will be transferred, I think multiple insert in single transaction will make the process faster.

Any suggestions/solutions are appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dousi3362 2013-04-20 21:18
    关注

    You could employ Connection#transactional($func):

    $connection = $em->getConnection();
    $connection->transactional (function ($connection) {
        $connection->insert('un_table_name', $associative_data_array1);
        $connection->insert('un_table_name', $associative_data_array2);
        ...
        $connection->insert('un_table_name', $associative_data_arrayN);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥30 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile