Răsfoiți Sursa

tec: Improve logs on DB connection failure (#2734)

For a moment, PHP wasn't able to connect to my database. I tried to
understand what happened, unfortunately, the logs were not very helpful
(it basically showed me information that I had in my configuration
file).

I changed the dsn string by the message from the raised exception, I
think it will be more useful.

Other call of Minz_PDOConnectionException are passing error messages
instead of string connection, so I took the opportunity to rename the
constructor argument.
Marien Fressinaud 6 ani în urmă
părinte
comite
f3d75b3ae5
2 a modificat fișierele cu 3 adăugiri și 4 ștergeri
  1. 1 1
      lib/Minz/ModelPdo.php
  2. 2 3
      lib/Minz/PDOConnectionException.php

+ 1 - 1
lib/Minz/ModelPdo.php

@@ -91,7 +91,7 @@ class Minz_ModelPdo {
 			self::$sharedPdo = $this->pdo;
 		} catch (Exception $e) {
 			throw new Minz_PDOConnectionException(
-				$dsn . $dsnParams,
+				$e->getMessage(),
 				$db['user'], Minz_Exception::ERROR
 			);
 		}

+ 2 - 3
lib/Minz/PDOConnectionException.php

@@ -1,8 +1,7 @@
 <?php
 class Minz_PDOConnectionException extends Minz_Exception {
-	public function __construct ($string_connection, $user, $code = self::ERROR) {
-		$message = 'Access to database is denied for `' . $user . '`'
-		         . ' (`' . $string_connection . '`)';
+	public function __construct ($error, $user, $code = self::ERROR) {
+		$message = 'Access to database is denied for `' . $user . '`: ' . $error;
 
 		parent::__construct ($message, $code);
 	}