服务报价 | 域名主机 | 网络营销 | 软件工具| [加入收藏]
 热线电话: #
当前位置: 主页 > php教程 > magento教程 >

让magento操作支持直接操作数据库方法

时间:2013-12-07 23:46来源:未知 作者:最模板 点击:
以下直接提供让magento操作支持直接操作数据库修改方法, 查: $read = Mage::getSingleton(core/resource)-getConnection(core_read); $sql = select * from `abc`; $result = $read-fetchAll($sql); //fetchRow查找一条 增,删

以下直接提供让magento操作支持直接操作数据库修改方法,  查:

    $read = Mage::getSingleton(“core/resource”)->getConnection(‘core_read’);
    $sql = “select * from `abc`”;
    $result = $read->fetchAll($sql);  //fetchRow查找一条
 
增,删,改
    $write = Mage::getSingleton(“core/resource”)->getConnection(‘core_write’);
     $sql = “insert into abc (name)values(‘hello’)”;
     $write->query($sql);
 
另一种写法:
     $write = Mage::getSingleton(“core/resource”)->getConnection(‘core_write’);
     $table = Mage::getSingleton(‘core/resource’)->getTableName(‘abc’);
     $write->insert($table,array(‘name’=>’hello’));
 
     $write = Mage::getSingleton(“core/resource”)->getConnection(‘core_write’);
    $table = Mage::getSingleton(‘core/resource’)->getTableName(‘abc’);
    $write->update($table,array(‘name’=>’abc’),array(‘id=?’=>3));
 
        $write = Mage::getSingleton(“core/resource”)->getConnection(‘core_write’);
    $table = Mage::getSingleton(‘core/resource’)->getTableName(‘abc’);
    $write->delete($table,array(‘id=?’=>3));
 
     $read = Mage::getSingleton(“core/resource”)->getConnection(‘core_read’);
    $table = Mage::getSingleton(‘core/resource’)->getTableName(‘abc’);
        $result = $read->select()->from(array(‘main_table’=>$table))->where(‘main_table.id=?’,3)->limit(1);
        $products=$read->fetchAll($result);
唯一不同的只是一个sql语句是组装的,一个是直接写的

(责任编辑:最模板)
顶一下
(3)
100%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
热点内容