dongxiong1935 2012-03-27 06:20 采纳率: 0%
浏览 41
已采纳

too long

Is batch insertion of records possible in cakephp ?

Kindly reply me if possible show me some samples ?

My Query will look like

INSERT INTO `job_places` (`id`, `country_code`, `group`, `name`) VALUES
 (1, 'DE', 3, 'Hamburg'),
 (6, 'FFF', 1, 'Frankfurt');
  • 写回答

1条回答 默认 最新

  • douwo8140 2012-03-27 06:24
    关注

    You have saveAll for things like this http://book.cakephp.org/1.3/view/1031/Saving-Your-Data

    Used to save (a) multiple individual records for a single model or (b) this record, as well as all associated records For saving multiple records of single model, $data needs to be a numerically indexed array of records like this:

    Array (
    
    >     [Article] => Array(
    >           [0] => Array
    >               (
    >                             [title] => title 1
    >                         )
    >           [1] => Array
    >               (
    >                             [title] => title 2
    >                         )
    >                 ) )
    

    In your example, you'll need to format your data array like:

    $data = array(
       'Job' => array(
          array('id' => 1, 'country_code' => 'DE', 'group' => 3, 'name' => 'Hamburg'),
          array('id' => 6, 'country_code' => 'FFF', 'group' => 1, 'name' => 'Frankfurt')
       )
    );
    
    $this->JobPlace->saveAll($data['Job']);
    

    Nothing beats trying when you are learning something, so give that a go and post any problems you are having rather than wait for someone to post the exact code where you can just copy paste.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)