查:

    $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);

相关文章:

  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-01-14
  • 2021-12-18
  • 2022-12-23
  • 2021-11-26
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-12-24
  • 2021-07-10
  • 2022-01-08
相关资源
相似解决方案