SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH SPECIAL OFFER: ENJOY 3 MONTHS OF SHOPIFY FOR $1/MONTH

Magento 2 get data in the env file and data in the table without going through the model.

1: A way to get programmatically the Prefix used for the tables (the prefix you set during the Magento installation)

Trong file Magento bạn có thể lấy các tiền tố được ghi trong file app/etc/env.php bằng cách sử dụng dòng code sau

use Magento\Framework\Serialize\SerializerInterface;
............
private $deploymentConfig;

public function __construct(
   DeploymentConfig $deploymentConfig
 ) {
    $this->deploymentConfig = $deploymentConfig;
}

............
public function getDataEnv(){
  // example get db table_prefix
   $tablePrefix = $this->deploymentConfig->get('db/table_prefix');
  // example get admin backend
  $tablePrefix = $this->deploymentConfig->get('backend/frontName');
}

call with objectManager

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$deploymentConfig = $objectManager->get('Magento\Framework\App\DeploymentConfig');
var_dump($deploymentConfig->get('db/table_prefix'));

2: How to get data straight from any table not in Magento 2

 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   = $this->_resource->getTableName('custom_test');

    $mapsDeleteQuery = "SELECT * FROM $tableName ORDER BY popularity DESC LIMIT 5";
    $result =  $connection->query($mapsDeleteQuery);
    //or
   $result = $connection->fetchAll("SELECT * FROM $tableName ORDER BY popularity DESC LIMIT 5");
   return $result;

}

call with objectManager

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$connection = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection  = $connection->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
$tableName   = $connection->getTableName('custom_test');
$result = $connection->fetchAll("SELECT * FROM $tableName ORDER BY popularity DESC LIMIT 5");
?>

Good luck