| version 1.4, 2014/10/15 13:00:16 |
version 1.5, 2017/06/09 15:05:06 |
|
|
| /** |
/** |
| * Database independent query interface |
* Database independent query interface |
| * |
* |
| * PHP versions 4 and 5 |
* PHP version 5 |
| * |
* |
| * LICENSE: This source file is subject to version 3.0 of the PHP license |
* LICENSE: This source file is subject to version 3.0 of the PHP license |
| * that is available through the world-wide-web at the following URI: |
* that is available through the world-wide-web at the following URI: |
| Line 426 define('DB_PORTABILITY_ALL', 63); |
|
| Line 426 define('DB_PORTABILITY_ALL', 63); |
|
| * @author Daniel Convissor <danielc@php.net> |
* @author Daniel Convissor <danielc@php.net> |
| * @copyright 1997-2007 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| * @version Release: 1.7.14RC2 |
* @version Release: 1.9.2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| */ |
*/ |
| class DB |
class DB |
| { |
{ |
| // {{{ &factory() |
// {{{ factory() |
| |
|
| /** |
/** |
| * Create a new DB object for the specified database type but don't |
* Create a new DB object for the specified database type but don't |
|
|
| * |
* |
| * @see DB_common::setOption() |
* @see DB_common::setOption() |
| */ |
*/ |
| static function &factory($type, $options = false) |
public static function factory($type, $options = false) |
| { |
{ |
| if (!is_array($options)) { |
if (!is_array($options)) { |
| $options = array('persistent' => $options); |
$options = array('persistent' => $options); |
|
|
| } |
} |
| |
|
| // }}} |
// }}} |
| // {{{ &connect() |
// {{{ connect() |
| |
|
| /** |
/** |
| * Create a new DB object including a connection to the specified database |
* Create a new DB object including a connection to the specified database |
|
|
| * 'portability' => DB_PORTABILITY_ALL, |
* 'portability' => DB_PORTABILITY_ALL, |
| * ); |
* ); |
| * |
* |
| * $db =& DB::connect($dsn, $options); |
* $db = DB::connect($dsn, $options); |
| * if (PEAR::isError($db)) { |
* if (PEAR::isError($db)) { |
| * die($db->getMessage()); |
* die($db->getMessage()); |
| * } |
* } |
|
|
| * |
* |
| * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError() |
* @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError() |
| */ |
*/ |
| static function &connect($dsn, $options = array()) |
public static function connect($dsn, $options = array()) |
| { |
{ |
| $dsninfo = DB::parseDSN($dsn); |
$dsninfo = DB::parseDSN($dsn); |
| $type = $dsninfo['phptype']; |
$type = $dsninfo['phptype']; |
|
|
| if (!class_exists($classname)) { |
if (!class_exists($classname)) { |
| $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, |
$tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, |
| "Unable to include the DB/{$type}.php" |
"Unable to include the DB/{$type}.php" |
| . " file for '$dsn'", |
. " file for '" |
| |
. DB::getDSNString($dsn, true) . "'", |
| 'DB_Error', true); |
'DB_Error', true); |
| return $tmp; |
return $tmp; |
| } |
} |
|
|
| * |
* |
| * @return string the DB API version number |
* @return string the DB API version number |
| */ |
*/ |
| static function apiVersion() |
function apiVersion() |
| { |
{ |
| return '1.7.14RC2'; |
return '1.9.2'; |
| } |
} |
| |
|
| // }}} |
// }}} |
|
|
| * |
* |
| * @return bool whether $value is DB_Error object |
* @return bool whether $value is DB_Error object |
| */ |
*/ |
| static function isError($value) |
public static function isError($value) |
| { |
{ |
| return is_a($value, 'DB_Error'); |
return is_object($value) && is_a($value, 'DB_Error'); |
| } |
} |
| |
|
| // }}} |
// }}} |
|
|
| * |
* |
| * @return bool whether $value is a DB_<driver> object |
* @return bool whether $value is a DB_<driver> object |
| */ |
*/ |
| static function isConnection($value) |
public static function isConnection($value) |
| { |
{ |
| return (is_object($value) && |
return (is_object($value) && |
| is_subclass_of($value, 'db_common') && |
is_subclass_of($value, 'db_common') && |
|
|
| * |
* |
| * @return boolean whether $query is a data manipulation query |
* @return boolean whether $query is a data manipulation query |
| */ |
*/ |
| static function isManip($query) |
public static function isManip($query) |
| { |
{ |
| $manips = 'INSERT|UPDATE|DELETE|REPLACE|' |
$manips = 'INSERT|UPDATE|DELETE|REPLACE|' |
| . 'CREATE|DROP|' |
. 'CREATE|DROP|' |
|
|
| * @return string the error message or false if the error code was |
* @return string the error message or false if the error code was |
| * not recognized |
* not recognized |
| */ |
*/ |
| static function errorMessage($value) |
public static function errorMessage($value) |
| { |
{ |
| static $errorMessages; |
static $errorMessages; |
| if (!isset($errorMessages)) { |
if (!isset($errorMessages)) { |
|
|
| * + username: User name for login |
* + username: User name for login |
| * + password: Password for login |
* + password: Password for login |
| */ |
*/ |
| static function parseDSN($dsn) |
public static function parseDSN($dsn) |
| { |
{ |
| $parsed = array( |
$parsed = array( |
| 'phptype' => false, |
'phptype' => false, |
|
|
| * @param boolean true to hide the password, false to include it |
* @param boolean true to hide the password, false to include it |
| * @return string |
* @return string |
| */ |
*/ |
| static function getDSNString($dsn, $hidePassword) { |
public static function getDSNString($dsn, $hidePassword) { |
| /* Calling parseDSN will ensure that we have all the array elements |
/* Calling parseDSN will ensure that we have all the array elements |
| * defined, and means that we deal with strings and array in the same |
* defined, and means that we deal with strings and array in the same |
| * manner. */ |
* manner. */ |
|
|
| * @author Stig Bakken <ssb@php.net> |
* @author Stig Bakken <ssb@php.net> |
| * @copyright 1997-2007 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| * @version Release: 1.7.14RC2 |
* @version Release: 1.9.2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| */ |
*/ |
| class DB_Error extends PEAR_Error |
class DB_Error extends PEAR_Error |
| Line 958 class DB_Error extends PEAR_Error |
|
| Line 959 class DB_Error extends PEAR_Error |
|
| * |
* |
| * @see PEAR_Error |
* @see PEAR_Error |
| */ |
*/ |
| function DB_Error($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, |
function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, |
| $level = E_USER_NOTICE, $debuginfo = null) |
$level = E_USER_NOTICE, $debuginfo = null) |
| { |
{ |
| if (is_int($code)) { |
if (is_int($code)) { |
| $this->PEAR_Error('DB Error: ' . DB::errorMessage($code), $code, |
parent::__construct('DB Error: ' . DB::errorMessage($code), $code, |
| $mode, $level, $debuginfo); |
$mode, $level, $debuginfo); |
| } else { |
} else { |
| $this->PEAR_Error("DB Error: $code", DB_ERROR, |
parent::__construct("DB Error: $code", DB_ERROR, |
| $mode, $level, $debuginfo); |
$mode, $level, $debuginfo); |
| } |
} |
| } |
} |
| |
|
| |
/** |
| |
* Workaround to both avoid the "Redefining already defined constructor" |
| |
* PHP error and provide backward compatibility in case someone is calling |
| |
* DB_Error() dynamically |
| |
*/ |
| |
public function __call($method, $arguments) |
| |
{ |
| |
if ($method == 'DB_Error') { |
| |
return call_user_func_array(array($this, '__construct'), $arguments); |
| |
} |
| |
trigger_error( |
| |
'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR |
| |
); |
| |
} |
| // }}} |
// }}} |
| } |
} |
| |
|
| Line 987 class DB_Error extends PEAR_Error |
|
| Line 1002 class DB_Error extends PEAR_Error |
|
| * @author Stig Bakken <ssb@php.net> |
* @author Stig Bakken <ssb@php.net> |
| * @copyright 1997-2007 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| * @version Release: 1.7.14RC2 |
* @version Release: 1.9.2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| */ |
*/ |
| class DB_result |
class DB_result |
| Line 1094 class DB_result |
|
| Line 1109 class DB_result |
|
| * |
* |
| * @return void |
* @return void |
| */ |
*/ |
| function DB_result(&$dbh, $result, $options = array()) |
function __construct(&$dbh, $result, $options = array()) |
| { |
{ |
| $this->autofree = $dbh->options['autofree']; |
$this->autofree = $dbh->options['autofree']; |
| $this->dbh = &$dbh; |
$this->dbh = &$dbh; |
| Line 1452 class DB_result |
|
| Line 1467 class DB_result |
|
| * @author Stig Bakken <ssb@php.net> |
* @author Stig Bakken <ssb@php.net> |
| * @copyright 1997-2007 The PHP Group |
* @copyright 1997-2007 The PHP Group |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| * @version Release: 1.7.14RC2 |
* @version Release: 1.9.2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| * @see DB_common::setFetchMode() |
* @see DB_common::setFetchMode() |
| */ |
*/ |
|
|
| * |
* |
| * @return void |
* @return void |
| */ |
*/ |
| function DB_row(&$arr) |
function __construct(&$arr) |
| { |
{ |
| foreach ($arr as $key => $value) { |
foreach ($arr as $key => $value) { |
| $this->$key = &$arr[$key]; |
$this->$key = &$arr[$key]; |