It is very easy to select, insert, delete and update the record in
magento site. 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
Select query to get the value form table
insert query
update query
delete query
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');
-
$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
-
$connection = Mage::getSingleton('core/resource')
-
->getConnection('core_write');
-
$connection->beginTransaction();
-
$fields = array();
-
$fields['name']= 'test';
-
$fields['age']='25';
-
$connection->insert('tablename', $fields);
-
$connection->commit();
-
$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();
-
$condition = array($connection->quoteInto('id=?', '1'));
-
$connection->delete('tablename', $condition);