How to Fetch Data from Magento2 Tables in .phtml files?
-
Nidhi Arora
- 8 years

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://envisionecommerce.com//
Download Blog