Fix initial DB check
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
/log.html
|
/log.html
|
||||||
/globalsettings.php
|
/globalsettings.php
|
||||||
inc/log.html
|
inc/log.html
|
||||||
|
/vendor/
|
||||||
27
inc/Db.php
27
inc/Db.php
@@ -57,16 +57,15 @@ class Db extends PhpObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!$this->oConnection->select_db($this->getConf('database')))
|
try {
|
||||||
{
|
$this->oConnection->select_db($this->getConf('database'));
|
||||||
$this->addError('Could not find database "'.$this->sDatabase.'"');
|
$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;
|
$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()
|
public function install()
|
||||||
{
|
{
|
||||||
//Create Database
|
//Create Database
|
||||||
$this->setQuery("DROP DATABASE IF EXISTS ".$this->sDatabase);
|
$this->setQuery("DROP DATABASE IF EXISTS ".$this->getConf('database'));
|
||||||
$this->setQuery("CREATE DATABASE ".$this->sDatabase." DEFAULT CHARACTER SET ".$this->getConf('encoding')." DEFAULT COLLATE ".$this->getConf('encoding')."_general_ci");
|
$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->sDatabase);
|
$this->oConnection->select_db($this->getConf('database'));
|
||||||
|
|
||||||
//Create tables
|
//Create tables
|
||||||
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
@array_walk($this->getInstallQueries(), array($this, 'setQuery'));
|
||||||
@@ -118,9 +117,7 @@ class Db extends PhpObject
|
|||||||
public function getBackup() {
|
public function getBackup() {
|
||||||
$sBackupFile = uniqid('backup_').'.sql';
|
$sBackupFile = uniqid('backup_').'.sql';
|
||||||
|
|
||||||
$sAppPath = '';
|
exec('mysqldump --user='.$this->getConf('user').' --password='.$this->getConf('pass').' '.$this->getConf('database').' --add-drop-table --result-file='.$sBackupFile);
|
||||||
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);
|
|
||||||
if(file_exists($sBackupFile)) {
|
if(file_exists($sBackupFile)) {
|
||||||
$sBackup = file_get_contents($sBackupFile);
|
$sBackup = file_get_contents($sBackupFile);
|
||||||
unlink($sBackupFile);
|
unlink($sBackupFile);
|
||||||
@@ -158,7 +155,7 @@ class Db extends PhpObject
|
|||||||
$asResult = $this->setQuery($sSql);
|
$asResult = $this->setQuery($sSql);
|
||||||
if($asResult === false)
|
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;
|
$bResult = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user