I have the following Magento 1 code and i would like to know the Magento 2 equivalent of the code.

I've looked around on the web but unable to find a proper solution.


I was able to find the function getConnection() at \Magento\Framework\DB\Query but it does not take any parameters.

Thanks in advance

  • please let me know if you have issue Commented May 15, 2017 at 11:36

1 Answer 1

    protected $_resource;
    public function __construct(
            \Magento\Framework\App\ResourceConnection $resource
        ) {
            $this->_resource = $resource;

Inside function,

$connection = $this->_resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$tablename = $connection->getTableName('sales_order');
$query = "your query";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.