Skip to content

Commit

Permalink
Added exit() function if database connection fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesallsup committed Mar 21, 2015
1 parent 22d6bdc commit c1a6532
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions upload/system/library/db/mpdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public function __construct($hostname, $username, $password, $database, $port =
$this->pdo = new \PDO("mysql:host=" . $hostname . ";port=" . $port . ";dbname=" . $database, $username, $password, array(\PDO::ATTR_PERSISTENT => true));
} catch(\PDOException $e) {
trigger_error('Error: Could not make a database link ( ' . $e->getMessage() . '). Error Code : ' . $e->getCode() . ' <br />');
exit();
}

$this->pdo->exec("SET NAMES 'utf8'");
Expand Down
2 changes: 2 additions & 0 deletions upload/system/library/db/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ final class MySQL {
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = mysql_connect($hostname, $username, $password)) {
trigger_error('Error: Could not make a database link using ' . $username . '@' . $hostname);
exit();
}

if (!mysql_select_db($database, $this->link)) {
trigger_error('Error: Could not connect to database ' . $database);
exit();
}

mysql_query("SET NAMES 'utf8'", $this->link);
Expand Down
1 change: 1 addition & 0 deletions upload/system/library/db/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public function __construct($hostname, $username, $password, $database) {

if ($this->link->connect_error) {
trigger_error('Error: Could not make a database link (' . $this->link->connect_errno . ') ' . $this->link->connect_error);
exit();
}

$this->link->set_charset("utf8");
Expand Down
2 changes: 2 additions & 0 deletions upload/system/library/db/postgre.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ final class Postgre {
public function __construct($hostname, $username, $password, $database) {
if (!$this->link = pg_connect('hostname=' . $hostname . ' username=' . $username . ' password=' . $password . ' database=' . $database)) {
trigger_error('Error: Could not make a database link using ' . $username . '@' . $hostname);
exit();
}

if (!mysql_select_db($database, $this->link)) {
trigger_error('Error: Could not connect to database ' . $database);
exit();
}

pg_query($this->link, "SET CLIENT_ENCODING TO 'UTF8'");
Expand Down

1 comment on commit c1a6532

@quincywu
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is

    trigger_error('Error: Could not connect to database ' . $database);
    exit();

better than

    exit('Error: Could not connect to database ' . $database);

Please sign in to comment.