Codeigniter何时使用insert_batch()

时间:2012-06-05 02:32:20

标签: php codeigniter

我正在Codeigniter中开发一个邮件队列,一次发送100条消息。我正在寻找最好的方法来实现这一目标并遇到$this->db->insert_batch()。它看起来很有用,但我无法找到有关何时或如何使用它的信息。有人用它来邮寄吗?

$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 个答案:

答案 0 :(得分:2)

您不能将$this->db->insert_batch()用于电子邮件目的(显然),因为它用于将数据插入数据库。你可以做的是改用CodeIgniter Email Class

$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();

在我看来,这是使用CodeIgniter向很多用户发送电子邮件的最佳方式。