0

I want to get a variable from a table of another module.

I followed this tutorial: https://fishpig.co.uk/magento/tutorials/direct-sql-queries/

$resource = Mage::getSingleton('core/resource');

$readConnection = $resource->getConnection('core_read');

$query = 'SELECT * FROM ' . $resource->getTableName('catalog/product');

$results = $readConnection->fetchAll($query);

var_dump($results);

and it works great for catalog/product table.

Then I tried to do the same thing for the custom table from a module:
$query = 'SELECT * FROM ' . $resource->getTableName('amtable/rate');

I concluded that the "table name" should be amtable/rate by following this comment and looking at the config.xml:

<global> <models> <amtable> <class>Amasty_Table_Model</class> <resourceModel>amtable_mysql4</resourceModel> </amtable> <amtable_mysql4> <class>Amasty_Table_Model_Mysql4</class> <entities> <method> <table>am_table_method</table> </method> <method_store> <table>am_table_method_store</table> </method_store> <rate> <table>am_table_rate</table> </rate> </entities> </amtable_mysql4>
But I get an error:
Cannot send headers; headers already sent in app/code/local/Jurgis/Mymodule/controllers/IndexController.php, line 15

Line 15 is: var_dump($results);

What could I be doing wrong or is there something I'm missing?

P.S. sorry about the formatting, couldn't figure out how to fix it.

3
  • yes, var_dump($results); is create s issue.It is try to reset header.Best way to use log
    – Amit Bera
    Apr 16, 2017 at 7:05
  • How do I print out an array like that using a log? Apr 16, 2017 at 8:05
  • 1
    print_r($var, true) will return the array as a string representation.
    – Brett
    Apr 16, 2017 at 12:09

1 Answer 1

0

Still not sure what was causing it, but it was fixed by adding exit(); after var_dump($results);

Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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