diff --git a/ykval-config.php b/ykval-config.php index 4ed16e8..fda083a 100644 --- a/ykval-config.php +++ b/ykval-config.php @@ -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", diff --git a/ykval-db.php b/ykval-db.php index b133149..106c4c4 100644 --- a/ykval-db.php +++ b/ykval-db.php @@ -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;