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.
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` varchar(50) NOT NULL, `username` varchar(20) NOT NULL, `password` varchar(20) NOT NULL, `created_date` int(11) NOT NULL, `is_active` varchar(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT...