zoukankan      html  css  js  c++  java
  • Magento中如何调用SQL语句

    I. 创建表结构和测试数据

    create table rooms(id int not null auto_increment, name varchar(100), primary key(id));
    insert into rooms values(1,'Royal Room');
    insert into rooms values(2,'Standard Room');

    II.创建 controllers/RoomController.php:

    1. <?php  
    2.     class Cartz_Hotel_RoomController extends Mage_Core_Controller_Front_Action{  
    3.        public function listingAction() {  
    4.           $handle = Mage::getSingleton('core/resource')->getConnection('core_write');  
    5.   
    6.           $query  = $handle->query('select name from rooms');  
    7.           while ($row = $query->fetch()) {  
    8.              $row = new Varien_Object($row);  
    9.              echo "<strong>" . $row->getName() . "</strong><br/>";  
    10.           }  
    11.   
    12.        }  
    13. }?>  

    在地址栏中输入: http://localhost/magento/index.php/hotel/room/listing, 页面将输出:

    Royal Room

    Standard Room

  • 相关阅读:
    拥有最多糖果的孩子
    求1+2+…+n
    网络-中间代理
    Header中的Referer属性表示
    ios13.4post请求出现网错错误 network err
    10.8&10.10
    9.23&9.27
    9.16&9.19
    校内模拟赛划水报告(9.9,9.11)
    男人八题 划水题解
  • 原文地址:https://www.cnblogs.com/focai/p/4459602.html
Copyright © 2011-2022 走看看