add db state

This commit is contained in:
2018-11-25 15:44:16 +01:00
parent 3d2bacf380
commit 260bc06370
3 changed files with 9 additions and 4 deletions

View File

@@ -10,10 +10,12 @@ class Db extends PhpObject
const DB_PEACHY = 'NO_ERR';
const DB_NO_CONN = 'ERR_1';
const DB_NO_DATA = 'ERR_2';
const DB_NO_TABLE = 'ERR_3';
const ID_TAG = 'id_';
//Database formats
const MONTH_FORMAT = 'Ym';
const DATE_FORMAT = 'Y-m-d';
const TIMESTAMP_FORMAT = 'Y-m-d H:i:s';
public $sDbState;
@@ -63,6 +65,10 @@ class Db extends PhpObject
$this->addError('Could not find database "'.$this->sDatabase.'"');
$this->sDbState = self::DB_NO_DATA;
}
elseif(empty($this->getArrayQuery("SHOW TABLES")))
{
$this->sDbState = self::DB_NO_TABLE;
}
else $this->sDbState = self::DB_PEACHY;
}
}
@@ -360,7 +366,6 @@ class Db extends PhpObject
//Cleaning values
$this->cleanSql($sTableName);
$this->cleanSql($iTableId);
$this->cleanSql($asData);
$this->cleanSql($asConstraints);
$asQueryValues = $this->addQuotes($asData);

View File

@@ -64,7 +64,7 @@ abstract class Main extends PhpObject
//$this->setLanguage($sLang);
//$this->oTranslator = new Translator($this->getLanguage());
$this->oDb = new Db(Settings::DB_SERVER, Settings::DB_LOGIN, Settings::DB_PASS, Settings::DB_NAME, $this->getSqlOptions() , Settings::DB_ENC);
if($this->oDb->sDbState == Db::DB_NO_DATA) $this->install();
if(in_array($this->oDb->sDbState, array(Db::DB_NO_DATA, Db::DB_NO_TABLE))) $this->install();
}
protected abstract function install();

View File

@@ -64,10 +64,10 @@ elseif($sAction!='' && !$bLoggedIn)
$sResult = $oCvTheque->apifunction();
break;
default:
$sResult = CvTheque::getJsonResult(false, Main::NOT_FOUND);
$sResult = Main::getJsonResult(false, Main::NOT_FOUND);
}
}
else $sResult = CvTheque::getJsonResult(false, Main::UNAUTHORIZED);
else $sResult = Main::getJsonResult(false, Main::UNAUTHORIZED);
}
elseif($bLoggedIn) $sResult = $oMain->getMainPage();
else $sResult = $oMain->getLogonPage();