Active Record – create (insert)

There are several ways to insert data into a database using CodeIgniter Active Record; for example, $this->db->insert() and $this->db->insert_batch(). The first will insert only one record at a time, and the second will insert an array of data as individual rows into the database; this can be quite useful if you know you need to insert more than one record at a time, thereby saving you the trouble of calling insert() more than once.

Getting ready

This is the SQL code required to support this recipe; you'll need to adapt it to your circumstances. Copy the following SQL code into your database:

CREATE TABLE IF NOT EXISTS `ch6_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(50) NOT NULL, `lastname` ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.