summaryrefslogtreecommitdiff
path: root/program/include/rcube_db.inc
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2006-03-14 21:13:07 +0000
committerthomascube <thomas@roundcube.net>2006-03-14 21:13:07 +0000
commit8affba5be0de8ec5b7bf71e12171ccb53ead497b (patch)
tree44554a9b9db111b8ab163d55ea2e5ad06fcf350a /program/include/rcube_db.inc
parenta2f2c5e1b7c8ed6d398eb6fd751f94553fa7d38e (diff)
Improved error handling in DB connection failure
Diffstat (limited to 'program/include/rcube_db.inc')
-rwxr-xr-xprogram/include/rcube_db.inc37
1 files changed, 30 insertions, 7 deletions
diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc
index 7cc29d225..573168887 100755
--- a/program/include/rcube_db.inc
+++ b/program/include/rcube_db.inc
@@ -35,7 +35,7 @@ require_once('DB.php');
* @package RoundCube Webmail
* @author David Saez Padros <david@ols.es>
* @author Thomas Bruederli <roundcube@gmail.com>
- * @version 1.16
+ * @version 1.17
* @link http://pear.php.net/package/DB
*/
class rcube_db
@@ -45,6 +45,9 @@ class rcube_db
var $db_connected = false; // Already connected ?
var $db_mode = ''; // Connection mode
var $db_handle = 0; // Connection handle
+ var $db_pconn = false; // Use persistent connections
+ var $db_error = false;
+ var $db_error_msg = '';
var $a_query_results = array('dummy');
var $last_res_id = 0;
@@ -56,13 +59,14 @@ class rcube_db
* @param string DSN for read/write operations
* @param string Optional DSN for read only operations
*/
- function __construct($db_dsnw, $db_dsnr='')
+ function __construct($db_dsnw, $db_dsnr='', $pconn=false)
{
if ($db_dsnr=='')
$db_dsnr=$db_dsnw;
$this->db_dsnw = $db_dsnw;
$this->db_dsnr = $db_dsnr;
+ $this->db_pconn = $pconn;
$dsn_array = DB::parseDSN($db_dsnw);
$this->db_provider = $dsn_array['phptype'];
@@ -74,9 +78,9 @@ class rcube_db
*
* @see rcube_db::__construct
*/
- function rcube_db($db_dsnw,$db_dsnr='')
+ function rcube_db($db_dsnw, $db_dsnr='', $pconn=false)
{
- $this->__construct($db_dsnw,$db_dsnr);
+ $this->__construct($db_dsnw, $db_dsnr);
}
@@ -90,12 +94,17 @@ class rcube_db
function dsn_connect($dsn)
{
// Use persistent connections if available
- $dbh = DB::connect($dsn, array('persistent' => TRUE));
+ $dbh = DB::connect($dsn, array('persistent' => $this->db_pconn));
if (DB::isError($dbh))
{
+ $this->db_error = TRUE;
+ $this->db_error_msg = $dbh->getMessage();
+
raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
- 'message' => $dbh->getMessage()), TRUE, FALSE);
+ 'message' => $this->db_error_msg), TRUE, FALSE);
+
+ return FALSE;
}
else if ($this->db_provider=='sqlite')
@@ -142,7 +151,18 @@ class rcube_db
$dsn = $this->db_dsnw;
$this->db_handle = $this->dsn_connect($dsn);
- $this->db_connected = true;
+ $this->db_connected = $this->db_handle ? TRUE : FALSE;
+ }
+
+
+ /**
+ * Getter for error state
+ *
+ * @param boolean True on error
+ */
+ function is_error()
+ {
+ return $this->db_error ? $this->db_error_msg : FALSE;
}
@@ -203,6 +223,9 @@ class rcube_db
$mode='w';
$this->db_connect($mode);
+
+ if (!$this->db_connected)
+ return FALSE;
if ($this->db_provider == 'sqlite')
$this->_sqlite_prepare();