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.
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 );
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 );