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);
    唯一不同的只是一个sql语句是组装的,一个是直接写的
  • 相关阅读:
    嵌入式编程中使用 do{...} while(0) 的解释
    ESP32学习笔记(一) 环境搭建与下载
    预告:准备开个坑,集中学习一下esp32模块
    【信号与系统】多项式化简方法
    nginx二级域名代理
    nginx配置ssl证书
    springBoot使用阿里云的证书
    vue-cli3项目开启less支持并引入短链接
    一键安装系列
    centos7增加swap
  • 原文地址:https://www.cnblogs.com/aqxinzhuan/p/3047094.html
Copyright © 2011-2022 走看看