<?php
/*
*
* TO Execute Multiple Raw Query In Magento 2
*
* */
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$conn = $resource->getConnection('write');
$sqlScript = file($sqlFile);
$query = '';
foreach ($sqlScript as $line) {
$startWith = substr(trim($line), 0 ,2);
$endWith = substr(trim($line), -1 ,1);
if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') continue;
$query = $query . $line;
if ($endWith == ';') {
$conn->query($query);
$query= '';
}
}
echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';
/*
*
* TO Execute Multiple Raw Query In Magento 2
*
* */
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$conn = $resource->getConnection('write');
$sqlScript = file($sqlFile);
$query = '';
foreach ($sqlScript as $line) {
$startWith = substr(trim($line), 0 ,2);
$endWith = substr(trim($line), -1 ,1);
if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') continue;
$query = $query . $line;
if ($endWith == ';') {
$conn->query($query);
$query= '';
}
}
echo '<div class="success-response sql-import-response">SQL file imported successfully</div>';
Comments
Post a Comment