Write a core database query in magento!!!!!!

You can write a core database query in magento which is a new stage for managing magento after all

this is a sample of how to write a core query means raw query

<?php echo '<h1> div area</h1>';
$sql = "SELECT sku  FROM catalog_product_entity ";
$data = Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll($sql);
if(!$data)echo "empty";
else
foreach ($data as $data)
echo $data['sku'].'<br/>';
?>

it show all the sku of your store’s product that means nice.

here i can anatomy the code as

  1. $sql stands for the query which you want to write
  2. $data stand for to collect data from the table. Here also come other thing that Mage::getSingleton(‘core/resource’) it is used for connecting the database and                       getConnection(‘core_read’) is used for connecting mode. That means is it connected as read mode or write mode. And last fetchAll($sql) means fetch all data in data array
  3. And rest as similar as php.

That’s ok.Have fun…

Advertisements

Tagged: , , , ,

3 thoughts on “Write a core database query in magento!!!!!!

  1. Reseller Hosting January 4, 2010 at 9:08 am

    Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

    • midpart January 4, 2010 at 9:28 am

      Thanx for you opinion:)

  2. Megan CLARK May 20, 2010 at 3:56 pm

    Undoubtfully nice post u have here. It would be great to read something more concerning such theme. Thnx for posting such info.

Comments are closed.

%d bloggers like this: