0
public function checkHelpful($rid ,$pid ,$uid )
{
    $connection = $this->objectManager->get('Magento\Framework\App\ResourceConnection');
    $tbl = $connection->getTableName('catalog/product_index_price');
    echo $table;
}

the output of this is 'catalog/product_index_price'. Not getting the exact table name with prefix.

2

Try this

 protected $_resource;

 public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Framework\App\ResourceConnection $resource
    ) {
    $this->_resource = $resource;
    parent::__construct($context);
}

public function execute()
{

    $connection  = $this->_resource->getConnection();
    $tableName   = $connection->getTableName('tablename_without_prefix'); // It will return table with prefix

    $mapsDeleteQuery = "your raw SQL Query";
    $connection->query($mapsDeleteQuery);
}
  • I implemented the same thing, but its giving me the same result as previous (table name without prefix). – Ashish Jagnani Aug 11 '16 at 11:07
0

I got the solution of this issue, instead of using this

$connection  = $this->_resource->getConnection();

We have to use this :

$connection  = $this->_resource; OR

$connection = $this->_objectManager->create('\Magento\Framework\App\ResourceConnection');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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