How to Fetch Data from Magento2 Tables in .phtml files?

  • Posted by Envision Ecommerce
  • /
  • January 11, 2017
how-to-fetch-data-from-magento2-tables-in-phtml-files

Today we’re going to cover fetching of data from Magento 2 tables. We can use the following codes for fetching such data via object manager. Here is how to complete this fetching process successfully:

$this->_resources = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\App\ResourceConnection');

$connection= $this->_resources->getConnection();

$themeTable = $this->_resources->getTableName('converge_token');

$sql = "select * from " . $themeTable . “where customer_id='$customerId'";

$result = $connection->fetchAll($sql);

If you follow the code mentioned above, you will be able to easily fetch data from Magento 2 tables. Keep looking out for our upcoming “How to” blog posts on Magento 2. If you have any issue or query regarding this “How to” blog, feel free to let us know via http://demo.envisionecommerce.com//