中国第一家开发出Magento企业版功能的团队,在Magento领域创造了众多第一,联系我们 qq:906082630 Email:906082630@qq.com

Magento开发 – 最专业的Magento开发团队

magento怎么调用SQL语句

Magento中调用SQL语句,首先需要创建表结构和测试数据
代码如下:
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’);
其次创建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/>”;
}
}
}?>
在地址栏中输入: <!– m –>
http://localhost/magento/index.php/hotel/room/listing<!– m –>
显示如下:
Royal Room
Standard Room