insert array values in database using codeigniter
$data = array(
'title' => 'My title',
'content' => 'My content',
'date' => 'My date'
);
$this->db->insert('my_table', $data);
Explanation:
Array Creation: Create an array named
$data
containing the values to be inserted into the database. This array holds key-value pairs where keys correspond to the column names in the database table, and values represent the data to be inserted into those columns.Array Initialization: Assign values to the keys in the
$data
array. For example,'title' => 'My title'
assigns the value'My title'
to the column named'title'
in the database.Database Insertion: Use CodeIgniter's
$this->db->insert()
method to insert the data into the specified table. The first parameter specifies the table name ('my_table'
), and the second parameter is the array ($data
) containing the values to be inserted. This method generates and executes an SQLINSERT
query based on the provided data.