Using select, insert, delete and update the record in magento site is very easy.
Following functions are helpful in magento site for database queries. You can also use this function outside magento environment with the help pf include “Mage.php” file form “app” folder like.
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel
Using select, insert, delete and update the record in magento site is very easy.
Following functions are helpful in magento site for database queries. You can also use this function outside magento environment with the help pf include “Mage.php” file form “app” folder like.
This is very simple to get data from database of magento site to frontend of magento site or another sites
require_once '../../app/Mage.php';
Mage::app('default');
Select query to get the value form table
$connection = Mage::getSingleton('core/resource')
->getConnection('core_read');
$select = $connection->select()
->from('tablename', array('*')) // select * from tablename or use array('id','name') selected values
->where('id=?',1) // where id =1
->group('name'); // group by name
$rowsArray = $connection->fetchAll($select); // return all rows
$rowArray =$connection->fetchRow($select); //return row
Insert query
$connection = Mage::getSingleton('core/resource')
->getConnection('core_write');
$connection->beginTransaction();
$fields = array();
$fields['name']= 'test';
$fields['age']='25';
$connection->insert('tablename', $fields);
$connection->commit();
update query
$connection = Mage::getSingleton('core/resource')
->getConnection('core_write');
$connection->beginTransaction();
$fields = array();
$fields['name'] = 'jony';
$where = $connection->quoteInto('id =?', '1');
$connection->update('tablename', $fields, $where);
$connection->commit();
delete query
$condition = array($connection->quoteInto('id=?', '1'));
$connection->delete('tablename', $condition);
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel
3 Responses
Thanks ajay….this post really helped for me….you done a great job….keep posting like this…
nice ajay…
Keep it up
From SVIT Vasad
Nice to see you brother !