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.

asked Apr 16, 2017 at 6:58
3
  • yes, var_dump($results); is create s issue.It is try to reset header.Best way to use log Commented Apr 16, 2017 at 7:05
  • How do I print out an array like that using a log? Commented Apr 16, 2017 at 8:05
  • 1
    print_r($var, true) will return the array as a string representation. Commented 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.

answered Apr 18, 2017 at 11:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.