Fix initial DB check
This commit is contained in:
27
inc/Db.php
27
inc/Db.php
@@ -57,16 +57,15 @@ class Db extends PhpObject
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->oConnection->select_db($this->getConf('database')))
|
||||
{
|
||||
$this->addError('Could not find database "'.$this->sDatabase.'"');
|
||||
try {
|
||||
$this->oConnection->select_db($this->getConf('database'));
|
||||
$this->sDbState = empty($this->getArrayQuery("SHOW TABLES"))?self::DB_NO_TABLE:self::DB_PEACHY;
|
||||
}
|
||||
catch(\Exception $oEx) {
|
||||
$this->addError('Could not find database "'.$this->getConf('database').'"');
|
||||
$this->sDbState = self::DB_NO_DATA;
|
||||
}
|
||||
elseif(empty($this->getArrayQuery("SHOW TABLES")))
|
||||
{
|
||||
$this->sDbState = self::DB_NO_TABLE;
|
||||
}
|
||||
else $this->sDbState = self::DB_PEACHY;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +106,9 @@ class Db extends PhpObject
|
||||
public function install()
|
||||
{
|
||||
//Create Database
|
||||
$this->setQuery("DROP DATABASE IF EXISTS ".$this->sDatabase);
|
||||
$this->setQuery("CREATE DATABASE ".$this->sDatabase." DEFAULT CHARACTER SET ".$this->getConf('encoding')." DEFAULT COLLATE ".$this->getConf('encoding')."_general_ci");
|
||||
$this->oConnection->select_db($this->sDatabase);
|
||||
$this->setQuery("DROP DATABASE IF EXISTS ".$this->getConf('database'));
|
||||
$this->setQuery("CREATE DATABASE ".$this->getConf('database')." DEFAULT CHARACTER SET ".$this->getConf('encoding')." DEFAULT COLLATE ".$this->getConf('encoding')."_general_ci");
|
||||
$this->oConnection->select_db($this->getConf('database'));
|
||||
|
||||
//Create tables
|
||||
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
||||
@@ -118,9 +117,7 @@ class Db extends PhpObject
|
||||
public function getBackup() {
|
||||
$sBackupFile = uniqid('backup_').'.sql';
|
||||
|
||||
$sAppPath = '';
|
||||
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $sAppPath = 'C:\ProgramData\xampp\mysql\bin\\';
|
||||
exec($sAppPath.'mysqldump --user='.$this->getConf('user').' --password='.$this->getConf('pass').' '.$this->getConf('database').' --add-drop-table --result-file='.$sBackupFile);
|
||||
exec('mysqldump --user='.$this->getConf('user').' --password='.$this->getConf('pass').' '.$this->getConf('database').' --add-drop-table --result-file='.$sBackupFile);
|
||||
if(file_exists($sBackupFile)) {
|
||||
$sBackup = file_get_contents($sBackupFile);
|
||||
unlink($sBackupFile);
|
||||
@@ -158,7 +155,7 @@ class Db extends PhpObject
|
||||
$asResult = $this->setQuery($sSql);
|
||||
if($asResult === false)
|
||||
{
|
||||
$this->addError('SQL failed with error: '.$this->db->error, $sSql);
|
||||
$this->addError('SQL failed with error: '.$this->oConnection->error, $sSql);
|
||||
$bResult = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user