O'Reilly logo

CodeIgniter 2 Cookbook by Rob Foster

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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` ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required