V.Magento中如何调用SQL语句

IV. 如何调用SQL语句

让我们在系列 文章I的基础上完成本文内容.

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:
    <?php
    class Cartz_Hotel_RoomController extends Mage_Core_Controller_Front_Action{
       public function listingAction() {
          $handle = Mage::getSingleton('core/resource')->getConnection('core_write');

          $query  = $handle->query('select name from rooms');
          while ($row = $query->fetch()) {
             $row = new Varien_Object($row);
             echo "<strong>" . $row->getName() . "</strong><br/>";
          }

       }
    }?>



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

你可能感兴趣的:(数据结构,sql,PHP,F#,bbs)