Magento 2 – How to Get Data from ‘directory_currency_rate’ Table

collection;currency-ratesdatabasemagento-2.1magento2

Table contains these columns.

enter image description here

I need to get data from this table 'directory_currency_rate'

which is come under this directory

/vendor/magento/module-directory/Model/Currency.php
/vendor/magento/module-directory/Model//ResourceModel/Currency.php

This model file does not have any collection.php file so can't able to get datas from this table.

Anyone know how to get data from this table ?

Thanks in advance

Best Answer

If you can not get using any class or methods, then you can use SQL select statement as below example.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('directory_currency_rate');

// SELECT DATA 
$fields = array('rate');
$sql = $connection->select()                      
                  ->from($tableName, $fields) // to select some particular fields                  
                  ->where('currency_from = ?', 'USD')
                  ->where('currency_to = ?', 'EUR'); // adding WHERE condition with AND
$result = $connection->fetchAll($sql); 
echo '<pre>'; print_r($result); echo '</pre>'; 
Related Topic