I have a custom module where my few DB fields are not being saved properly. I can see the values selected in $model->getData(); but it does not reflects in my Database.

try {   

       echo '<pre>';print_r($model->getData());echo '<br>';// shows correct values selected
        echo '<pre>';print_r($model->getData());exit;// shows correct values saved


The above code shows me correct values being selected and processed, but not saved in DB.

Is there any way where I can print the INSERT query and check what is caysing the issue ?

Please Help !!!


  • 1
    try clearing cache – Pradeep Sanku Jun 13 '14 at 10:16
  • I am working on localhost – Mark Jun 13 '14 at 10:21
  • like mentioned above by pradeepsanku, clear the cache. Even if the cache is disabled the table definition is still cached. – Marius Jun 13 '14 at 11:13
  • Okay, I cleared the cache and still it does not saved properly. Could anyone let me know how to print insert query while saving the $model – Mark Jun 13 '14 at 11:21
  • please try to specify that are you using a controller in custom module to set the some values in session. Or using anywhere set->session function. – Ami Kamboj Jun 14 '14 at 4:08

Magento queries run through Zend_Db_Adapter_Abstract::query() located in lib/Zend/Db/Adapter/Abstract.php

In the query method you can add something like this:

if (strpos($sql, 'INSERT') === 0) {

to print all the INSERT queries and data bound to them (for debugging only, of course).

  • This is a core hack, and should be done very carefully. But it does work. – Aepod Feb 15 '15 at 16:17

This is built-in, but somewhat guarded. Once again, n98-magerun comes to the rescue:

n98 dev:log:db --on

Now, you can see all queries with parameters in var/debug/pdo_mysql.log.


Using Z-Ray on Zend Server you can see all SQL queries. It trivializes this problem, and you dont have to do any core hacking. You can see it in action: http://serverdemo.zend.com/magento/

Not the answer you're looking for? Browse other questions tagged or ask your own question.