Adding batch loads
This commit is contained in:
38
inc/db.php
38
inc/db.php
@@ -122,6 +122,44 @@ class Db extends PhpObject
|
|||||||
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function loadFile($sFilePath) {
|
||||||
|
set_time_limit(0);
|
||||||
|
$bResult = false;
|
||||||
|
|
||||||
|
if(file_exists($sFilePath))
|
||||||
|
{
|
||||||
|
$sContent = file_get_contents($sFilePath);
|
||||||
|
$sContent = ToolBox::fixEOL($sContent);
|
||||||
|
if(str_replace(ToolBox::FILE_EOL, '', $sContent)!='')
|
||||||
|
{
|
||||||
|
$asLines = explode(ToolBox::FILE_EOL, $sContent);
|
||||||
|
$sSql = '';
|
||||||
|
foreach ($asLines as $sLine)
|
||||||
|
{
|
||||||
|
$sSql .= trim($sLine);
|
||||||
|
if(substr($sSql, -1)==';') //Multi line SQL
|
||||||
|
{
|
||||||
|
$asResult = $this->setQuery($sSql);
|
||||||
|
if($asResult === false)
|
||||||
|
{
|
||||||
|
$this->addError('SQL failed with error: '.$this->db->error, $sSql);
|
||||||
|
$bResult = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$bResult = true;
|
||||||
|
$sSql = '';
|
||||||
|
}
|
||||||
|
else $sSql .= " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else $this->addError('File is empty: '.basename($sFilePath));
|
||||||
|
}
|
||||||
|
else $this->addError('File not found: '.$sFilePath);
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
|
||||||
//For debug purposes
|
//For debug purposes
|
||||||
public function getFullInstallQuery()
|
public function getFullInstallQuery()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user