* DB::isWarning().
*/
-define("DB_WARNING", -1000);
-define("DB_WARNING_READ_ONLY", -1001);
+define('DB_WARNING', -1000);
+define('DB_WARNING_READ_ONLY', -1001);
/*
* These constants are used when storing information about prepared
* into your database).
*/
-define("DB_PARAM_SCALAR", 1);
-define("DB_PARAM_OPAQUE", 2);
+define('DB_PARAM_SCALAR', 1);
+define('DB_PARAM_OPAQUE', 2);
/*
* These constants define different ways of returning binary data
* hex format, for example the string "123" would become "313233".
*/
-define("DB_BINMODE_PASSTHRU", 1);
-define("DB_BINMODE_RETURN", 2);
-define("DB_BINMODE_CONVERT", 3);
+define('DB_BINMODE_PASSTHRU', 1);
+define('DB_BINMODE_RETURN', 2);
+define('DB_BINMODE_CONVERT', 3);
/**
* This is a special constant that tells DB the user hasn't specified
* any particular get mode, so the default should be used.
*/
-define("DB_FETCHMODE_DEFAULT", 0);
+define('DB_FETCHMODE_DEFAULT', 0);
/**
* Column data indexed by numbers, ordered from 0 and up
*/
-define("DB_FETCHMODE_ORDERED", 1);
+define('DB_FETCHMODE_ORDERED', 1);
/**
* Column data indexed by column names
*/
-define("DB_FETCHMODE_ASSOC", 2);
+define('DB_FETCHMODE_ASSOC', 2);
/**
* For multi-dimensional results: normally the first level of arrays
* is the column name, and the second level the row number.
*/
-define("DB_FETCHMODE_FLIPPED", 4);
+define('DB_FETCHMODE_FLIPPED', 4);
/* for compatibility */
-define("DB_GETMODE_ORDERED", DB_FETCHMODE_ORDERED);
-define("DB_GETMODE_ASSOC", DB_FETCHMODE_ASSOC);
-define("DB_GETMODE_FLIPPED", DB_FETCHMODE_FLIPPED);
+define('DB_GETMODE_ORDERED', DB_FETCHMODE_ORDERED);
+define('DB_GETMODE_ASSOC', DB_FETCHMODE_ASSOC);
+define('DB_GETMODE_FLIPPED', DB_FETCHMODE_FLIPPED);
/**
* The main "DB" class is simply a container class with some static
* DB The main DB class. This is simply a utility class
* with some "static" methods for creating DB objects as
* well as common utility functions for other DB classes.
- *
+ *
* DB_common The base for each DB implementation. Provides default
* | implementations (in OO lingo virtual methods) for
* | the actual DB implementations as well as a bunch of
function &factory($type)
{
- @include_once("DB/${type}.php");
+ @include_once("DB/${type}.php");
- $classname = "DB_${type}";
- @$obj =& new $classname;
+ $classname = "DB_${type}";
+ @$obj =& new $classname;
- if (!$obj) {
- return new DB_Error(DB_ERROR_NOT_FOUND);
- }
+ if (!$obj) {
+ return new DB_Error(DB_ERROR_NOT_FOUND);
+ }
- return $obj;
+ return $obj;
}
/**
$dsninfo = DB::parseDSN($dsn);
}
$type = $dsninfo["phptype"];
-
- @include_once "DB/${type}.php";
+
+ @include_once "DB/${type}.php";
$classname = "DB_${type}";
@$obj =& new $classname;
*/
function apiVersion()
{
- return 2;
+ return 2;
}
/**
*/
function isError($value)
{
- return (is_object($value) &&
- (get_class($value) == 'db_error' ||
- is_subclass_of($value, 'db_error')));
+ return (is_object($value) &&
+ (get_class($value) == 'db_error' ||
+ is_subclass_of($value, 'db_error')));
}
/**
*/
function isWarning($value)
{
- return is_object($value) &&
- (get_class( $value ) == "db_warning" ||
- is_subclass_of($value, "db_warning"));
+ return is_object($value) &&
+ (get_class( $value ) == "db_warning" ||
+ is_subclass_of($value, "db_warning"));
}
/**
*/
function errorMessage($value)
{
- if (!isset($errorMessages)) {
- $errorMessages = array(
- DB_ERROR => "unknown error",
- DB_ERROR_ALREADY_EXISTS => "already exists",
- DB_ERROR_CANNOT_CREATE => "can not create",
- DB_ERROR_CANNOT_DELETE => "can not delete",
- DB_ERROR_CANNOT_DROP => "can not drop",
- DB_ERROR_CONSTRAINT => "constraint violation",
- DB_ERROR_DIVZERO => "division by zero",
- DB_ERROR_INVALID => "invalid",
- DB_ERROR_INVALID_DATE => "invalid date or time",
- DB_ERROR_INVALID_NUMBER => "invalid number",
- DB_ERROR_MISMATCH => "mismatch",
- DB_ERROR_NODBSELECTED => "no database selected",
- DB_ERROR_NOSUCHFIELD => "no such field",
- DB_ERROR_NOSUCHTABLE => "no such table",
- DB_ERROR_NOT_CAPABLE => "DB backend not capable",
- DB_ERROR_NOT_FOUND => "not found",
- DB_ERROR_NOT_LOCKED => "not locked",
- DB_ERROR_SYNTAX => "syntax error",
- DB_ERROR_UNSUPPORTED => "not supported",
- DB_ERROR_VALUE_COUNT_ON_ROW => "value count on row",
- DB_OK => "no error",
- DB_WARNING => "unknown warning",
- DB_WARNING_READ_ONLY => "read only"
- );
- }
-
- if (DB::isError($value)) {
- $value = $value->code;
- }
-
- return $errorMessages[$value];
+ if (!isset($errorMessages)) {
+ $errorMessages = array(
+ DB_ERROR => 'unknown error',
+ DB_ERROR_ALREADY_EXISTS => 'already exists',
+ DB_ERROR_CANNOT_CREATE => 'can not create',
+ DB_ERROR_CANNOT_DELETE => 'can not delete',
+ DB_ERROR_CANNOT_DROP => 'can not drop',
+ DB_ERROR_CONSTRAINT => 'constraint violation',
+ DB_ERROR_DIVZERO => 'division by zero',
+ DB_ERROR_INVALID => 'invalid',
+ DB_ERROR_INVALID_DATE => 'invalid date or time',
+ DB_ERROR_INVALID_NUMBER => 'invalid number',
+ DB_ERROR_MISMATCH => 'mismatch',
+ DB_ERROR_NODBSELECTED => 'no database selected',
+ DB_ERROR_NOSUCHFIELD => 'no such field',
+ DB_ERROR_NOSUCHTABLE => 'no such table',
+ DB_ERROR_NOT_CAPABLE => 'DB backend not capable',
+ DB_ERROR_NOT_FOUND => 'not found',
+ DB_ERROR_NOT_LOCKED => 'not locked',
+ DB_ERROR_SYNTAX => 'syntax error',
+ DB_ERROR_UNSUPPORTED => 'not supported',
+ DB_ERROR_VALUE_COUNT_ON_ROW => 'value count on row',
+ DB_OK => 'no error',
+ DB_WARNING => 'unknown warning',
+ DB_WARNING_READ_ONLY => 'read only'
+ );
+ }
+
+ if (DB::isError($value)) {
+ $value = $value->code;
+ }
+
+ return $errorMessages[$value];
}
/**
$parsed['phptype'] = $str;
$parsed['dbsyntax'] = $str;
}
-
+
if (empty($dsn)) {
return $parsed;
}
function assertExtension($name)
{
if (!extension_loaded($name)) {
- $dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
+ $dlext = (substr(PHP_OS, 0, 3) == 'WIN') ? '.dll' : '.so';
@dl($name . $dlext);
}
if (!extension_loaded($name)) {
*/
function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
- $level = E_USER_NOTICE, $debuginfo = null)
+ $level = E_USER_NOTICE, $debuginfo = null)
{
- if (is_int($code)) {
- $this->PEAR_Error("DB Error: " . DB::errorMessage( $code ), $code, $mode, $level, $debuginfo);
- } else {
- $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
- }
+ if (is_int($code)) {
+ $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
+ } else {
+ $this->PEAR_Error("DB Error: $code", DB_ERROR, $mode, $level, $debuginfo);
+ }
}
}
*/
function DB_Warning($code = DB_WARNING, $mode = PEAR_ERROR_RETURN,
- $level = E_USER_NOTICE, $debuginfo = null)
+ $level = E_USER_NOTICE, $debuginfo = null)
{
- if (is_int($code)) {
- $this->PEAR_Error("DB Warning: " . DB::errorMessage( $code ), $code, $mode, $level, $debuginfo);
- } else {
- $this->PEAR_Error("DB Warning: $code", 0, $mode, $level, $debuginfo);
- }
+ if (is_int($code)) {
+ $this->PEAR_Error('DB Warning: ' . DB::errorMessage($code), $code, $mode, $level, $debuginfo);
+ } else {
+ $this->PEAR_Error("DB Warning: $code", 0, $mode, $level, $debuginfo);
+ }
}
}
function DB_result(&$dbh, $result)
{
- $this->dbh = &$dbh;
- $this->result = $result;
+ $this->dbh = &$dbh;
+ $this->result = $result;
}
/**
*/
function fetchRow($fetchmode = DB_FETCHMODE_DEFAULT)
{
- if ($fetchmode == DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->dbh->fetchmode;
- }
- return $this->dbh->fetchRow($this->result, $fetchmode);
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->dbh->fetchmode;
+ }
+ return $this->dbh->fetchRow($this->result, $fetchmode);
}
/**
*/
function fetchInto(&$arr, $fetchmode = DB_FETCHMODE_DEFAULT)
{
- if ($fetchmode == DB_FETCHMODE_DEFAULT) {
- $fetchmode = $this->dbh->fetchmode;
- }
- return $this->dbh->fetchInto($this->result, $arr, $fetchmode);
+ if ($fetchmode == DB_FETCHMODE_DEFAULT) {
+ $fetchmode = $this->dbh->fetchmode;
+ }
+ return $this->dbh->fetchInto($this->result, $arr, $fetchmode);
}
/**
*/
function numCols()
{
- return $this->dbh->numCols($this->result);
+ return $this->dbh->numCols($this->result);
}
/**
*/
function free()
{
- $err = $this->dbh->freeResult($this->result);
- if(DB::isError($err)) {
- return $err;
- }
- $this->result = false;
- return true;
+ $err = $this->dbh->freeResult($this->result);
+ if(DB::isError($err)) {
+ return $err;
+ }
+ $this->result = false;
+ return true;
}
}