ds2128629 2012-06-05 02:32
浏览 92
已采纳

Codeigniter何时使用insert_batch()

I'm developing a mailing queue in Codeigniter that sends 100 messages at a time. I'm searching for the best way to do this and came across $this->db->insert_batch(). It looks useful but I can't find information on when or how to use it. Has anyone used it for mailing purposes?

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name' ,
      'date' => 'My date'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name' ,
      'date' => 'Another date'
   )
);

$this->db->insert_batch('mytable', $data); 

// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
  • 写回答

1条回答 默认 最新

  • douzhai7873 2012-06-05 02:44
    关注

    You can't use $this->db->insert_batch() for emailing purposes (obviously) because it's used to insert data into the database. What you can do is use CodeIgniter Email Class instead.

    $this->load->library('email');
    
    $this->email->from('your@email.tld', 'Your Name');
    $this->email->to('your@email.tld'); // Send the email to yourself to see how it looks
    $this->email->bcc('...'); // Pass in a comma-delimited list of email addresses or an array
    
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');
    
    $this->email->send();
    

    In my opinion, this would be the best way to send an email to a lot of users using CodeIgniter.

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

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?