Fix initial DB check

This commit is contained in:
2023-02-17 18:54:49 +01:00
parent f5e165a446
commit 98670dc33f
2 changed files with 13 additions and 15 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/log.html /log.html
/globalsettings.php /globalsettings.php
inc/log.html inc/log.html
/vendor/

View File

@@ -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;
} }