Please, how we can use sql queries on controller? i am using Magento 2 and this is my controller:
<?php
namespace Demo\Demo\Controller\Demo;
class Demo extends \Magento\Framework\App\Action\Action
{
public function execute()
{
}
}
Please, how we can use sql queries on controller? i am using Magento 2 and this is my controller:
<?php
namespace Demo\Demo\Controller\Demo;
class Demo extends \Magento\Framework\App\Action\Action
{
public function execute()
{
}
}
You can use ResourceConnection Method if you wish to use sql queries in Controller.
$resource = $this->_objectManager->create('\Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$values = $connection->fetchAll('select * from `table` ');
You should not do it in controller. ResourceModel Layer is resposible for data persistence