insert query , update query , delete query and select query in magento

Insert Query:-

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

Update Query:-

$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);

Delete Query:-

$write_connection = Mage::getSingleton('core/resource')->getConnection('core_write'); 
$where = array($write_connection ->quoteInto('tableId =?', '1'));
$write_connection->delete('tablename',$where);

Select Query:-

$read_connection = Mage::getSingleton('core/resource')->getConnection('core_read'); 
$query_data="select * from tablename";
$rowsArray = $read_connection->fetchAll($query_data); // return all rows
$rowArray =  $read_connection->fetchRow($query_data);   //return row
  • Hi, this is a comment.
    To delete a comment, just log in and view the post's comments. There you will have the option to edit or delete them.