- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020
05:06 AM
09-15-2020
05:06 AM
Hi
I need to run simple sql query with fetchOne in magento 2
How I can do code for it
Can someone help.
Solved! Go to Solution.
Labels:
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020
05:22 AM
09-15-2020
05:22 AM
Please try with the below code:
protected $_resource;
$this->_resource = $resource;
$table=$this->_resource->getTableName('tablename'); $this->_connection = $this->_resource->getConnection(); $query = 'SELECT * FROM '.$table; $collection = $this->_connection->fetchOne($query );
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Problem Solved! Click Kudos & Accept as Solution!
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020
05:22 AM
09-15-2020
05:22 AM
Please try with the below code:
protected $_resource;
$this->_resource = $resource;
$table=$this->_resource->getTableName('tablename'); $this->_connection = $this->_resource->getConnection(); $query = 'SELECT * FROM '.$table; $collection = $this->_connection->fetchOne($query );
Hope this helps you!
Problem Solved! Click Kudos & Accept as Solution!
Problem Solved! Click Kudos & Accept as Solution!