How to call SQL statements in Magento

Source: Internet
Author: User
Tags vars

I. Creating table structures and test data

CREATE table rooms (ID int not NULL auto_increment, name varchar (+), primary key (ID));
INSERT into rooms VALUES (1, ' Royal ');
INSERT into rooms VALUES (2, "standard");

II. Create controllers/roomcontroller.php:

SOURCE print?
  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. $query = $handle->query (' select name from rooms ');
  6. While ($row = $query->fetch ()) {
  7. $row = new Varien_object ($row);
  8. echo "<strong>". $row->getname ().  "</strong><br/>";
  9. }
  10. }
  11. }?>

In the Address bar, enter: http://localhost/magento/index.php/hotel/room/listing, the page will output:

Royal

Standard

How to call SQL statements in Magento

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.