Custom Query in magento


<?php
//select query
$read = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’);
//make connection
$qry = “select name FROM user_data WHERE id=1 LIMIT 1 “; 
//query
$res = $read->fetchRow($qry); //fetch row
$name = $res[‘name’]; //outputs name

//other form
$qry = “select name FROM user_data WHERE namer LIKE ‘%a%’ “;
//query
$res = $read->fetchAll($qry); //get array

//Insert query
$write = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’);
$sql = “INSERT INTO user_data values (?,?)”; //insert query
$write->query($sql, array(‘name’,’pass’)); //write to database

?>

8 thoughts on “Custom Query in magento

  1. Hi this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding knowledge so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

  2. Have you ever considered creating an ebook or guest authoring on other
    websites? I have a blog centered on the same subjects you discuss and
    would love to have you share some stories/information.

    I know my subscribers would value your work.

    If you’re even remotely interested, feel free to send me an e mail.

  3. Hey! I’m at work surfing around your blog from my new iphone 4! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the outstanding work!

  4. Sweet blog! I found it while surfing around on Yahoo
    News. Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there! Many thanks

  5. Unquestionably believe that which you stated. Your favorite justification appeared
    to be on the net the simplest thing to be aware of. I say to you, I definitely get
    irked while people consider worries that they just do not
    know about. You managed to hit the nail upon the top and defined out
    the whole thing without having side effect , people can take
    a signal. Will likely be back to get more. Thanks

Leave a comment