zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    Python第二
    Python第一讲以及计算机基础
    MySQL第五讲
    MySQL第四讲
    MySQL第三讲
    MySQL第一讲概论
    MySQL日常笔记第二讲
    Linux修改用户组
    XAMPP中proftpd的简明配置方法
    解决php configure: error: Cannot find ldap libraries in /usr/lib.错误
  • 原文地址:https://www.cnblogs.com/zhengyanbin2016/p/5732092.html
Copyright © 2011-2022 走看看