summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2005-10-03 20:51:31 +0000
committerthomascube <thomas@roundcube.net>2005-10-03 20:51:31 +0000
commitadf95dde7bb32716d4152528a1c6d8eab3fadcb2 (patch)
tree0d0f0bf9d8d85035a8dfb7803364588f10535b80
parent627330f670ad7921044592ca72819f7ee6ed3fa0 (diff)
Changed file encoding to unix/UTF-8
-rwxr-xr-xprogram/include/rcube_db.inc138
1 files changed, 69 insertions, 69 deletions
diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc
index 96f120f3c..fe838da4c 100755
--- a/program/include/rcube_db.inc
+++ b/program/include/rcube_db.inc
@@ -13,7 +13,7 @@
| See http://pear.php.net/package/DB |
| |
+-----------------------------------------------------------------------+
- | Author: Thomas Bruederli <roundcube@gmail.com> |
+ | Author: David Saez Padros <david@ols.es> |
+-----------------------------------------------------------------------+
$Id$
@@ -24,11 +24,11 @@ require_once('DB.php');
class rcube_db
{
- var $db_dsnw; // DSN for write operations
- var $db_dsnr; // DSN for read operations
- var $db_connected=false; // Already connected ?
- var $db_mode=''; // Connection mode
- var $db_handle=0; // Connection handle
+ var $db_dsnw; // DSN for write operations
+ var $db_dsnr; // DSN for read operations
+ var $db_connected=false; // Already connected ?
+ var $db_mode=''; // Connection mode
+ var $db_handle=0; // Connection handle
var $a_query_results = array('dummy');
var $last_res_id = 0;
@@ -36,8 +36,8 @@ class rcube_db
// PHP 5 constructor
function __construct($db_dsnw,$db_dsnr='')
{
- if ($db_dsnr=='') $db_dsnr=$db_dsnw;
-
+ if ($db_dsnr=='') $db_dsnr=$db_dsnw;
+
$this->db_dsnw = $db_dsnw;
$this->db_dsnr = $db_dsnr;
}
@@ -48,83 +48,83 @@ class rcube_db
$this->__construct($db_dsnw,$db_dsnr);
}
- // Connect to specific database
- function dsn_connect($dsn)
- {
- // Use persistent connections if available
-
- $dbh = DB::connect($dsn, array('persistent' => $true));
+ // Connect to specific database
+ function dsn_connect($dsn)
+ {
+ // Use persistent connections if available
+
+ $dbh = DB::connect($dsn, array('persistent' => $true));
- if (DB::isError($dbh))
- raise_error(array('code' => 500,
+ if (DB::isError($dbh))
+ raise_error(array('code' => 500,
'type' => 'db',
'line' => __LINE__,
'file' => __FILE__,
'message' => $dbh->getMessage()), TRUE, FALSE);
- return $dbh;
- }
-
- // Connect to appropiate databse
- function db_connect ($mode)
- {
- // Already connected
-
- if ($this->db_connected)
- {
- // no replication, current connection is ok
- if ($this->db_dsnw==$this->db_dsnr) return;
-
- // connected to master, current connection is ok
- if ($this->db_mode=='w') return;
-
- // Same mode, current connection is ok
- if ($this->db_mode==$mode) return;
- }
-
- if ($mode=='r')
- $dsn=$this->db_dsnr;
- else
- $dsn=$this->db_dsnw;
-
- $this->db_handle = $this->dsn_connect($dsn);
- $this->db_connected = true;
- $this->db_mode = $mode;
- }
-
- // Query database (read operations)
-
+ return $dbh;
+ }
+
+ // Connect to appropiate databse
+ function db_connect ($mode)
+ {
+ // Already connected
+
+ if ($this->db_connected)
+ {
+ // no replication, current connection is ok
+ if ($this->db_dsnw==$this->db_dsnr) return;
+
+ // connected to master, current connection is ok
+ if ($this->db_mode=='w') return;
+
+ // Same mode, current connection is ok
+ if ($this->db_mode==$mode) return;
+ }
+
+ if ($mode=='r')
+ $dsn=$this->db_dsnr;
+ else
+ $dsn=$this->db_dsnw;
+
+ $this->db_handle = $this->dsn_connect($dsn);
+ $this->db_connected = true;
+ $this->db_mode = $mode;
+ }
+
+ // Query database (read operations)
+
function query($query)
{
- // Read or write ?
-
- if (strtolower(trim(substr($query,0,6)))=='select')
- $mode='r';
- else
- {
- $mode='w';
- }
-
- $this->db_connect($mode);
+ // Read or write ?
+
+ if (strtolower(trim(substr($query,0,6)))=='select')
+ $mode='r';
+ else
+ {
+ $mode='w';
+ }
+
+ $this->db_connect($mode);
$result = $this->db_handle->query($query);
if (DB::isError($result))
- raise_error( array('code' => 500, 'type' => 'db', 'line' => __LINE__,
- 'file' => __FILE__,
- 'message' => $result->getMessage()), TRUE, FALSE);
+ raise_error( array('code' => 500, 'type' => 'db', 'line' => __LINE__,
+ 'file' => __FILE__,
+ 'message' => $result->getMessage()), TRUE, FALSE);
return $this->_add_result($result, $query);
}
- function db_execute ($query)
- {
- db_connect('w');
+ function db_execute ($query)
+ {
+ db_connect('w');
- $result = $this->db_handle->query($query);
+ $result = $this->db_handle->query($query);
- }
-
- function num_rows($res_id=NULL)
+ }
+
+ function num_rows($res_id=NULL)
{
if (!$this->db_handle)
return FALSE;
@@ -185,7 +185,7 @@ class rcube_db
// sql error occured
if (DB::isError($res))
{
- raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $res->getMessage() . " Query: " . preg_replace('/[\r\n]+\s*/', ' ', $query)), TRUE, FALSE);
+ raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 'message' => $res->getMessage() . " Query: " . substr(preg_replace('/[\r\n]+\s*/', ' ', $query), 0, 1024)), TRUE, FALSE);
return FALSE;
}
else