From ea9e014adae880dea2aa7b7520bb03b9be50bcdd Mon Sep 17 00:00:00 2001 From: Kevin Duret <duret.kevin@gmail.com> Date: Tue, 5 Jun 2018 13:35:19 +0200 Subject: [PATCH] enh(pdo): do not manage pdo exception on lowest level of application (#6265) * enh(pdo): do not manage pdo exception on lowest level of application * fix(pdo): fix exception thrown in centreon DB class --- www/class/centreonDB.class.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/www/class/centreonDB.class.php b/www/class/centreonDB.class.php index af6f7d6e91..7ec79da5e5 100644 --- a/www/class/centreonDB.class.php +++ b/www/class/centreonDB.class.php @@ -143,7 +143,7 @@ class CentreonDB extends \PDO } } } - + public function autoCommit($val) { /* Deprecated */ @@ -227,15 +227,6 @@ class CentreonDB extends \PDO $parameters = array($parameters); } - /* - * LOG all request - */ - if ($this->debug) { - $string = str_replace("`", "", $queryString); - $string = str_replace('*', "\*", $string); - $this->log->insertLog(2, " QUERY : " . $string); - } - /* * Launch request */ @@ -249,8 +240,13 @@ class CentreonDB extends \PDO } $this->queryNumber++; $this->successQueryNumber++; - } catch (PDOException $e) { - echo $e->getMessage(); + } catch (\PDOException $e) { + if ($this->debug) { + $string = str_replace("`", "", $queryString); + $string = str_replace('*', "\*", $string); + $this->log->insertLog(2, " QUERY : " . $string); + } + throw new \PDOException($e->getMessage(), $e->getCode()); } return $sth; @@ -272,10 +268,11 @@ class CentreonDB extends \PDO $result = $this->query($query_string); $rows = $result->fetchAll(); $this->requestSuccessful++; - } catch (\Exception $e) { + } catch (\PDOException $e) { if ($this->debug) { $this->log->insertLog(2, $e->getMessage() . " QUERY : " . $query_string); } + throw new \PDOException($e->getMessage(), $e->getCode()); } return $rows; @@ -313,9 +310,9 @@ class CentreonDB extends \PDO } return $number; } - + /* - * checks if there is malicious injection + * checks if there is malicious injection */ public static function checkInjection($sString) { -- GitLab