CyberJunkie
CyberJunkie

Reputation: 22684

Codeigniter when to use 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')

Upvotes: 0

Views: 2223

Answers (1)

Fad
Fad

Reputation: 9858

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('[email protected]', 'Your Name');
$this->email->to('[email protected]'); // 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.

Upvotes: 2

Related Questions