Magento数据库MySQL读写配置
//数据库读取配置
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
//数据库写入配置
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
//读写配置的功能
$readMethods = get_class_methods(get_class($read));foreach($readMethods as $r){echo $r."\n";}
$writeMethods = get_class_methods(get_class($write));foreach($writeMethods as $r){echo $r."\n";}
Magento Read Query,返回一个数组
$results = $read->fetchAll("select * from customer_entity where email like '%@sbboke.com'");
var_dump($results[0]);
foreach($results as $r)
{
var_dump($r);
}
Magento插入查询
$write->insert(
"A_TABLE_NANE",
array("a_column_name" => value, "a_column_name" => value)
);
Magento更新查询
$write->update(
"A_TABLE_NANE",
array("a_column_name" => value, "a_column_name" => value),
"entity_id=18"
);
Magento删除查询
$write->delete(
"A_TABLE_NANE",
"entity_id=18"
);
Magento Raw查询。它可用于创建,读取,更新和删除操作
//raw query Varien_Db_Statement_Pdo_Mysql
$customers = $read->query("select * from customer_entity");
var_dump($customers);
foreach($customers as $c)
{
var_dump($c);
}