core class in magento2
-
13-12-2019 - |
Question
how can we use
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$tableName = $resource->getTableName('sales/order');
in magento2?
What is the replacement of core/resource in magento2?
I have tried with \Magento\Framework\Setup\SchemaSetupInterface
but its not instantiating in block or model classes.
Solution
\Magento\Framework\App\ResourceConnection is analog for 'core/resource' alias.
Pay attention on:
M2 don't have separation on read/write connection, so use $resource->getConnection('default');
M2 don't use aliases for table names, so use $resource->getTableName('sales_order');
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange