PDO exceptions for error handling
This commit is contained in:
parent
1d7b929871
commit
8e63827c0f
@ -289,6 +289,7 @@ class Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->db = new PDO("$db_proto:host=$db_host;dbname=$db_name", $db_user, $db_pass);
|
$this->db = new PDO("$db_proto:host=$db_host;dbname=$db_name", $db_user, $db_pass);
|
||||||
|
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
|
|
||||||
if(isset($cache_dsn) && !empty($cache_dsn)) {
|
if(isset($cache_dsn) && !empty($cache_dsn)) {
|
||||||
$matches = array();
|
$matches = array();
|
||||||
@ -304,36 +305,14 @@ class Database {
|
|||||||
$this->cache = new NoCache();
|
$this->cache = new NoCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->db) {
|
|
||||||
$this->engine->init($this->db);
|
$this->engine->init($this->db);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
$version = VERSION;
|
|
||||||
print "
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Internal error - Shimmie-$version</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Internal error: Could not connect to database
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute an SQL query and return an PDO resultset
|
* Execute an SQL query and return an PDO resultset
|
||||||
*/
|
*/
|
||||||
public function execute($query, $args=array()) {
|
public function execute($query, $args=array()) {
|
||||||
$result = $this->db->query($query, $args);
|
$result = $this->db->query($query, $args);
|
||||||
if($result === False) {
|
|
||||||
print "SQL Error: " . $this->db->ErrorMsg();
|
|
||||||
print "<br>Query: $query";
|
|
||||||
print "<br>Args: "; print_r($args);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,13 +320,7 @@ class Database {
|
|||||||
* Execute an SQL query and return a 2D array
|
* Execute an SQL query and return a 2D array
|
||||||
*/
|
*/
|
||||||
public function get_all($query, $args=array()) {
|
public function get_all($query, $args=array()) {
|
||||||
$result = $this->db->GetAll($query, $args);
|
$result = $this->db->fetchAll($query, $args);
|
||||||
if($result === False) {
|
|
||||||
print "SQL Error: " . $this->db->ErrorMsg();
|
|
||||||
print "<br>Query: $query";
|
|
||||||
print "<br>Args: "; print_r($args);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,13 +328,7 @@ class Database {
|
|||||||
* Execute an SQL query and return a single row
|
* Execute an SQL query and return a single row
|
||||||
*/
|
*/
|
||||||
public function get_row($query, $args=array()) {
|
public function get_row($query, $args=array()) {
|
||||||
$result = $this->db->GetRow($query, $args);
|
$result = $this->db->fetch($query, $args);
|
||||||
if($result === False) {
|
|
||||||
print "SQL Error: " . $this->db->ErrorMsg();
|
|
||||||
print "<br>Query: $query";
|
|
||||||
print "<br>Args: "; print_r($args);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
if(count($result) == 0) {
|
if(count($result) == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ try {
|
|||||||
|
|
||||||
// connect to the database
|
// connect to the database
|
||||||
$database = new Database();
|
$database = new Database();
|
||||||
$database->db->fnExecute = '_count_execs';
|
//$database->db->fnExecute = '_count_execs'; // FIXME: PDO equivalent
|
||||||
$config = new DatabaseConfig($database);
|
$config = new DatabaseConfig($database);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user