Recent Posts


Query Bind Syntax


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This one is for me, since I seem to forget Magento’s query binding syntax every time I stay away from it fore more than a week.

$sql = "select foo
from bar
where baz = ?";

$query = Mage::getSingleton('core/resource')->getConnection('core_read')

while($row = $query->fetch())

The biggest gotcha is not put your bind params (?) in quotation marks

where baz = '?' ";

The confusing the parsing engine, and makes it think there aren’t the right number of tokens. There’s also a named paramater syntax, which my old man tendencies avoids.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 21st September 2011

email hidden; JavaScript is required