summaryrefslogtreecommitdiffstats
path: root/lib/class/dba.class.php
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-02-02 18:45:06 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-02-02 18:53:02 -0500
commit4cbb5db6dfcf190a49bb3feac945059565554927 (patch)
treedf2f62c5916b7576181b7271804977858ec0a765 /lib/class/dba.class.php
parent4acffa613dc6ac23a7a92f26555832165a7e6ef6 (diff)
downloadampache-4cbb5db6dfcf190a49bb3feac945059565554927.tar.gz
ampache-4cbb5db6dfcf190a49bb3feac945059565554927.tar.bz2
ampache-4cbb5db6dfcf190a49bb3feac945059565554927.zip
Make Dba::query() a bit more correct
Check the DB handle and the statement handle before we try to use them.
Diffstat (limited to 'lib/class/dba.class.php')
-rw-r--r--lib/class/dba.class.php15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/class/dba.class.php b/lib/class/dba.class.php
index 58af7947..dce5708f 100644
--- a/lib/class/dba.class.php
+++ b/lib/class/dba.class.php
@@ -59,20 +59,29 @@ class Dba {
// care about here.
debug_event('Query', $sql . ' ' . @json_encode($params), 6);
+ $dbh = self::dbh();
+ if (!$dbh) {
+ debug_event('Dba', 'Error: failed to get database handle', 1);
+ return false;
+ }
+
// Run the query
if ($params) {
- $stmt = self::dbh()->prepare($sql);
+ $stmt = $dbh->prepare($sql);
$stmt->execute($params);
}
else {
- $stmt = self::dbh()->query($sql);
+ $stmt = $dbh->query($sql);
}
// Save the query, to make debug easier
self::$_sql = $sql;
self::$stats['query']++;
- if ($stmt->errorCode() && $stmt->errorCode() != '00000') {
+ if (!$stmt) {
+ debug_event('Dba', 'Error: ' . json_encode($dbh->errorInfo()), 1);
+ }
+ else if ($stmt->errorCode() && $stmt->errorCode() != '00000') {
debug_event('Dba', 'Error: ' . json_encode($stmt->errorInfo()), 1);
}