How to Get Data From Custom Database Table in Magento 2

How to Get Data From Custom Database Table in Magento 2

Magento 2 offers to fetch the data from the default database table.

However, to get data from custom database table in Magento 2, one will need to implement the solution below.

You can use this code to get data for a custom module you developed or any custom feature for which you’ll need data from a custom database table.

Also, if you want to display any custom data on the frontend, for example, show customers’ mobile number on the cart page or My Account, you’ll have to fetch the data for implementing the same.

Method to get data from custom database table in Magento 2:

Create Data.php in app/code/[Vendor]/[Module]/Helper

Now, you can use a helper function to get the custom table model collection as per your requirement.

That’s it.

Any doubts about the topic or its implementation?

If so, mention them in the Comments section below. I’d be happy to help you out.

Do share the solution with Magento community via social media.

Thank you.

5
(based on 16 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a reply:

Your email address will not be published.

SUBSCRIBE
3.8
(based on 5 Reviews)