Update Query

Update Query:- It is used to update 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;
$where = $write_connection ->quoteInto(‘tableId =?’, field_id);
$write_connection->update(‘tablename’, $fields_arr, $where);

[/php]

Example:- Suppose, you have to update records name and age of the employee table which has employee’s 1.

[php]
$write_connection = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$fields_arr = array();
$fields_arr[‘name’] = ‘John’;
$fields_arr[‘age’] = ’29’;
$where = $write_connection ->quoteInto(‘tableId =?’, ‘1’);
$write_connection->update(‘tablename’, $fields_arr, $where);
[/php]