Search code examples
codeignitercodeigniter-2

Insert into database without specifying field names


I'm using the following code to insert a single register of address in the database:

$this->db->insert('address', $address);

The command above inserts with:
Inesert into table(columns) values(values)

I would like to know, is there command to insert without having to specify the field names, using CodeIgniter framework and if possible, without having to handwrite the insert sql query?

Like:
Insert into table values(values)


Solution

  • Yes it can be done with raw sql But not on CI's db->insert function, Why? because the function/method needs 2 parameters first is the table name and second an array of key and values where the keys is the DB table's column name and value is the column value.

    Unless you create one or modify the existing function, but until that NO it cannot be done.

    Try a different approach like using $this->db->query('..query ..'); where you put your own SQL