1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-20 21:54:20 +01:00

Add code to let the db reconnect after errors.

Set PDO error mode to throw exceptions so we can catch them and do things.
This commit is contained in:
Klas Lindfors 2012-05-22 13:15:25 +02:00
parent 53aaceedb9
commit 3de7ca3c8b
2 changed files with 9 additions and 4 deletions

View File

@ -5,7 +5,7 @@ $baseParams = array ();
$baseParams['__YKVAL_DB_DSN__'] = "mysql:dbname=ykval;host=127.0.0.1";
$baseParams['__YKVAL_DB_USER__'] = 'ykval_verifier';
$baseParams['__YKVAL_DB_PW__'] = 'lab';
$baseParams['__YKVAL_DB_OPTIONS__'] = array();
$baseParams['__YKVAL_DB_OPTIONS__'] = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
# For the validation server sync
$baseParams['__YKVAL_SYNC_POOL__'] = array("http://api2.example.com/wsapi/2.0/sync",

View File

@ -104,12 +104,17 @@ class Db
}
private function query($query, $returnresult=false) {
if($this->dbh) {
if(!$this->isConnected()) {
$this->connect();
}
if($this->isConnected()) {
$this->myLog->log(LOG_DEBUG, 'DB query is: ' . $query);
$this->result = $this->dbh->query($query);
if (! $this->result){
try {
$this->result = $this->dbh->query($query);
} catch (PDOException $e) {
$this->myLog->log(LOG_INFO, 'Database query error: ' . preg_replace('/\n/',' ',print_r($this->dbh->errorInfo(), true)));
$this->dbh = Null;
return false;
}
if ($returnresult) return $this->result;