Insert Query

Insert Query:- It is used to insert record into the custom table.

Syntax:-
[php]
$write_connection = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$fields_arr = array();
$fields_arr[‘field_name1’] = value_1;
$fields_arr[‘field_name2’] = value_2;
……………………………….
$fields_arr[‘field_namen’] = value_n;
$write_connection ->insert(‘tablename’, $fields_arr);
[/php]

Example:- Suppose, you have to insert records name and age into the employee table.

[php]
$write_connection = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$fields_arr = array();
$fields_arr[‘name’] = ‘John’;
$fields_arr[‘age’] = ’29’;
$write_connection ->insert(’employee’, $fields_arr);
[/php]