| | |
| | | // | Author: Lukas Smith <smith@pooteeweet.org> | |
| | | // +----------------------------------------------------------------------+ |
| | | // |
| | | // $Id: MDB2.php 292663 2009-12-26 18:21:46Z quipo $ |
| | | // $Id: MDB2.php 295587 2010-02-28 17:16:38Z quipo $ |
| | | // |
| | | |
| | | /** |
| | |
| | | */ |
| | | class MDB2 |
| | | { |
| | | // {{{ function setOptions(&$db, $options) |
| | | // {{{ function setOptions($db, $options) |
| | | |
| | | /** |
| | | * set option array in an exiting database object |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function setOptions(&$db, $options) |
| | | static function setOptions($db, $options) |
| | | { |
| | | if (is_array($options)) { |
| | | foreach ($options as $option => $value) { |
| | |
| | | * @static |
| | | * @access public |
| | | */ |
| | | function classExists($classname) |
| | | static function classExists($classname) |
| | | { |
| | | if (version_compare(phpversion(), "5.0", ">=")) { |
| | | return class_exists($classname, false); |
| | | } |
| | | return class_exists($classname); |
| | | return class_exists($classname, false); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function loadClass($class_name, $debug) |
| | | static function loadClass($class_name, $debug) |
| | | { |
| | | if (!MDB2::classExists($class_name)) { |
| | | $file_name = str_replace('_', DIRECTORY_SEPARATOR, $class_name).'.php'; |
| | |
| | | } else { |
| | | $msg = "unable to load class '$class_name' from file '$file_name'"; |
| | | } |
| | | $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); |
| | | $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); |
| | | return $err; |
| | | } |
| | | if (!MDB2::classExists($class_name)) { |
| | | $msg = "unable to load class '$class_name' from file '$file_name'"; |
| | | $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); |
| | | $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, $msg); |
| | | return $err; |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &factory($dsn, $options = false) |
| | | // {{{ function factory($dsn, $options = false) |
| | | |
| | | /** |
| | | * Create a new MDB2 object for the specified database type |
| | | * |
| | | * IMPORTANT: In order for MDB2 to work properly it is necessary that |
| | | * you make sure that you work with a reference of the original |
| | | * object instead of a copy (this is a PHP4 quirk). |
| | | * |
| | | * For example: |
| | | * $db =& MDB2::factory($dsn); |
| | | * ^^ |
| | | * And not: |
| | | * $db = MDB2::factory($dsn); |
| | | * |
| | | * @param mixed 'data source name', see the MDB2::parseDSN |
| | | * method for a description of the dsn format. |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &factory($dsn, $options = false) |
| | | static function factory($dsn, $options = false) |
| | | { |
| | | $dsninfo = MDB2::parseDSN($dsn); |
| | | if (empty($dsninfo['phptype'])) { |
| | | $err =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, |
| | | $err = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, |
| | | null, null, 'no RDBMS driver specified'); |
| | | return $err; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &connect($dsn, $options = false) |
| | | // {{{ function connect($dsn, $options = false) |
| | | |
| | | /** |
| | | * Create a new MDB2_Driver_* connection object and connect to the specified |
| | | * database |
| | | * |
| | | * IMPORTANT: In order for MDB2 to work properly it is necessary that |
| | | * you make sure that you work with a reference of the original |
| | | * object instead of a copy (this is a PHP4 quirk). |
| | | * |
| | | * For example: |
| | | * $db =& MDB2::connect($dsn); |
| | | * ^^ |
| | | * And not: |
| | | * $db = MDB2::connect($dsn); |
| | | * ^^ |
| | | * |
| | | * @param mixed $dsn 'data source name', see the MDB2::parseDSN |
| | | * method for a description of the dsn format. |
| | |
| | | * @access public |
| | | * @see MDB2::parseDSN |
| | | */ |
| | | function &connect($dsn, $options = false) |
| | | static function connect($dsn, $options = false) |
| | | { |
| | | $db =& MDB2::factory($dsn, $options); |
| | | $db = MDB2::factory($dsn, $options); |
| | | if (PEAR::isError($db)) { |
| | | return $db; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &singleton($dsn = null, $options = false) |
| | | // {{{ function singleton($dsn = null, $options = false) |
| | | |
| | | /** |
| | | * Returns a MDB2 connection with the requested DSN. |
| | | * A new MDB2 connection object is only created if no object with the |
| | | * requested DSN exists yet. |
| | | * |
| | | * IMPORTANT: In order for MDB2 to work properly it is necessary that |
| | | * you make sure that you work with a reference of the original |
| | | * object instead of a copy (this is a PHP4 quirk). |
| | | * |
| | | * For example: |
| | | * $db =& MDB2::singleton($dsn); |
| | | * ^^ |
| | | * And not: |
| | | * $db = MDB2::singleton($dsn); |
| | | * ^^ |
| | | * |
| | | * @param mixed 'data source name', see the MDB2::parseDSN |
| | | * method for a description of the dsn format. |
| | |
| | | * @access public |
| | | * @see MDB2::parseDSN |
| | | */ |
| | | function &singleton($dsn = null, $options = false) |
| | | static function singleton($dsn = null, $options = false) |
| | | { |
| | | if ($dsn) { |
| | | $dsninfo = MDB2::parseDSN($dsn); |
| | |
| | | } |
| | | } |
| | | } elseif (is_array($GLOBALS['_MDB2_databases']) && reset($GLOBALS['_MDB2_databases'])) { |
| | | $db =& $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])]; |
| | | return $db; |
| | | return $GLOBALS['_MDB2_databases'][key($GLOBALS['_MDB2_databases'])]; |
| | | } |
| | | $db =& MDB2::factory($dsn, $options); |
| | | $db = MDB2::factory($dsn, $options); |
| | | return $db; |
| | | } |
| | | |
| | |
| | | * @param array $arr2 |
| | | * @return boolean |
| | | */ |
| | | function areEquals($arr1, $arr2) |
| | | static function areEquals($arr1, $arr2) |
| | | { |
| | | if (count($arr1) != count($arr2)) { |
| | | return false; |
| | |
| | | /** |
| | | * load a file (like 'Date') |
| | | * |
| | | * @param string name of the file in the MDB2 directory (without '.php') |
| | | * @param string $file name of the file in the MDB2 directory (without '.php') |
| | | * |
| | | * @return string name of the file that was included |
| | | * @return string name of the file that was included |
| | | * |
| | | * @access public |
| | | */ |
| | | function loadFile($file) |
| | | static function loadFile($file) |
| | | { |
| | | $file_name = 'MDB2'.DIRECTORY_SEPARATOR.$file.'.php'; |
| | | if (!MDB2::fileExists($file_name)) { |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function isError($data, $code = null) |
| | | static function isError($data, $code = null) |
| | | { |
| | | if (is_a($data, 'MDB2_Error')) { |
| | | if ($data instanceof MDB2_Error) { |
| | | if (null === $code) { |
| | | return true; |
| | | } elseif (is_string($code)) { |
| | | return $data->getMessage() === $code; |
| | | } else { |
| | | $code = (array)$code; |
| | | return in_array($data->getCode(), $code); |
| | | } |
| | | if (is_string($code)) { |
| | | return $data->getMessage() === $code; |
| | | } |
| | | return in_array($data->getCode(), (array)$code); |
| | | } |
| | | return false; |
| | | } |
| | |
| | | * @param mixed value to test |
| | | * |
| | | * @return bool whether $value is a MDB2 connection |
| | | * |
| | | * @access public |
| | | */ |
| | | function isConnection($value) |
| | | { |
| | | return is_a($value, 'MDB2_Driver_Common'); |
| | | return ($value instanceof MDB2_Driver_Common); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | /** |
| | | * Tell whether a value is a MDB2 result |
| | | * |
| | | * @param mixed value to test |
| | | * @param mixed $value value to test |
| | | * |
| | | * @return bool whether $value is a MDB2 result |
| | | * @return bool whether $value is a MDB2 result |
| | | * |
| | | * @access public |
| | | * @access public |
| | | */ |
| | | function isResult($value) |
| | | { |
| | | return is_a($value, 'MDB2_Result'); |
| | | return ($value instanceof MDB2_Result); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | /** |
| | | * Tell whether a value is a MDB2 result implementing the common interface |
| | | * |
| | | * @param mixed value to test |
| | | * @param mixed $value value to test |
| | | * |
| | | * @return bool whether $value is a MDB2 result implementing the common interface |
| | | * @return bool whether $value is a MDB2 result implementing the common interface |
| | | * |
| | | * @access public |
| | | */ |
| | | function isResultCommon($value) |
| | | static function isResultCommon($value) |
| | | { |
| | | return is_a($value, 'MDB2_Result_Common'); |
| | | return ($value instanceof MDB2_Result_Common); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | */ |
| | | function isStatement($value) |
| | | { |
| | | return is_a($value, 'MDB2_Statement_Common'); |
| | | return ($value instanceof MDB2_Statement_Common); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * @access public |
| | | * @author Tomas V.V.Cox <cox@idecnet.com> |
| | | */ |
| | | function parseDSN($dsn) |
| | | static function parseDSN($dsn) |
| | | { |
| | | $parsed = $GLOBALS['_MDB2_dsninfo_default']; |
| | | |
| | |
| | | if ($dsn) { |
| | | // /database |
| | | if (($pos = strpos($dsn, '?')) === false) { |
| | | $parsed['database'] = $dsn; |
| | | $parsed['database'] = rawurldecode($dsn); |
| | | // /database?param1=value1¶m2=value2 |
| | | } else { |
| | | $parsed['database'] = substr($dsn, 0, $pos); |
| | | $parsed['database'] = rawurldecode(substr($dsn, 0, $pos)); |
| | | $dsn = substr($dsn, $pos + 1); |
| | | if (strpos($dsn, '&') !== false) { |
| | | $opts = explode('&', $dsn); |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function fileExists($file) |
| | | static function fileExists($file) |
| | | { |
| | | // safe_mode does notwork with is_readable() |
| | | if (!@ini_get('safe_mode')) { |
| | |
| | | * @param int what error level to use for $mode & PEAR_ERROR_TRIGGER |
| | | * @param mixed additional debug info, such as the last query |
| | | */ |
| | | function MDB2_Error($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN, |
| | | function __construct($code = MDB2_ERROR, $mode = PEAR_ERROR_RETURN, |
| | | $level = E_USER_NOTICE, $debuginfo = null, $dummy = null) |
| | | { |
| | | if (null === $code) { |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function MDB2_Driver_Common() |
| | | |
| | | /** |
| | | * PHP 4 Constructor |
| | | */ |
| | | function MDB2_Driver_Common() |
| | | { |
| | | $this->destructor_registered = false; |
| | | $this->__construct(); |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ destructor: function __destruct() |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | $err =& PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); |
| | | $err = PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true); |
| | | if ($err->getMode() !== PEAR_ERROR_RETURN |
| | | && isset($this->nested_transaction_counter) && !$this->has_transaction_error) { |
| | | $this->has_transaction_error =& $err; |
| | | $this->has_transaction_error = $err; |
| | | } |
| | | return $err; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &loadModule($module, $property = null, $phptype_specific = null) |
| | | // {{{ function loadModule($module, $property = null, $phptype_specific = null) |
| | | |
| | | /** |
| | | * loads a module |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &loadModule($module, $property = null, $phptype_specific = null) |
| | | function loadModule($module, $property = null, $phptype_specific = null) |
| | | { |
| | | if (!$property) { |
| | | $property = strtolower($module); |
| | |
| | | } |
| | | |
| | | if (!MDB2::classExists($class_name)) { |
| | | $err =& $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_LOADMODULE, null, null, |
| | | "unable to load module '$module' into property '$property'", __FUNCTION__); |
| | | return $err; |
| | | } |
| | | $this->{$property} = new $class_name($this->db_index); |
| | | $this->modules[$module] =& $this->{$property}; |
| | | $this->modules[$module] = $this->{$property}; |
| | | if ($version) { |
| | | // this will be used in the connect method to determine if the module |
| | | // needs to be loaded with a different version if the server |
| | |
| | | $module = $this->options['modules'][$match[1]]; |
| | | $method = strtolower($match[2]).$match[3]; |
| | | if (!isset($this->modules[$module]) || !is_object($this->modules[$module])) { |
| | | $result =& $this->loadModule($module); |
| | | $result = $this->loadModule($module); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &standaloneQuery($query, $types = null, $is_manip = false) |
| | | function standaloneQuery($query, $types = null, $is_manip = false) |
| | | { |
| | | $offset = $this->offset; |
| | | $limit = $this->limit; |
| | |
| | | return $connection; |
| | | } |
| | | |
| | | $result =& $this->_doQuery($query, $is_manip, $connection, false); |
| | | $result = $this->_doQuery($query, $is_manip, $connection, false); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | $affected_rows = $this->_affectedRows($connection, $result); |
| | | return $affected_rows; |
| | | } |
| | | $result =& $this->_wrapResult($result, $types, true, false, $limit, $offset); |
| | | $result = $this->_wrapResult($result, $types, true, false, $limit, $offset); |
| | | return $result; |
| | | } |
| | | |
| | |
| | | * |
| | | * @access protected |
| | | */ |
| | | function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null) |
| | | function _doQuery($query, $is_manip = false, $connection = null, $database_name = null) |
| | | { |
| | | $this->last_query = $query; |
| | | $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre')); |
| | |
| | | } |
| | | $query = $result; |
| | | } |
| | | $err =& $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | 'method not implemented', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &exec($query) |
| | | function exec($query) |
| | | { |
| | | $offset = $this->offset; |
| | | $limit = $this->limit; |
| | |
| | | return $connection; |
| | | } |
| | | |
| | | $result =& $this->_doQuery($query, true, $connection, $this->database_name); |
| | | $result = $this->_doQuery($query, true, $connection, $this->database_name); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &query($query, $types = null, $result_class = true, $result_wrap_class = false) |
| | | function query($query, $types = null, $result_class = true, $result_wrap_class = false) |
| | | { |
| | | $offset = $this->offset; |
| | | $limit = $this->limit; |
| | |
| | | return $connection; |
| | | } |
| | | |
| | | $result =& $this->_doQuery($query, false, $connection, $this->database_name); |
| | | $result = $this->_doQuery($query, false, $connection, $this->database_name); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | | |
| | | $result =& $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset); |
| | | $result = $this->_wrapResult($result, $types, $result_class, $result_wrap_class, $limit, $offset); |
| | | return $result; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &_wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null) |
| | | // {{{ function _wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = false, $limit = null, $offset = null) |
| | | |
| | | /** |
| | | * wrap a result set into the correct class |
| | |
| | | * |
| | | * @access protected |
| | | */ |
| | | function &_wrapResult($result_resource, $types = array(), $result_class = true, |
| | | function _wrapResult($result_resource, $types = array(), $result_class = true, |
| | | $result_wrap_class = false, $limit = null, $offset = null) |
| | | { |
| | | if ($types === true) { |
| | |
| | | if ($result_class) { |
| | | $class_name = sprintf($result_class, $this->phptype); |
| | | if (!MDB2::classExists($class_name)) { |
| | | $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | 'result class does not exist '.$class_name, __FUNCTION__); |
| | | return $err; |
| | | } |
| | | $result = new $class_name($this, $result_resource, $limit, $offset); |
| | | if (!MDB2::isResultCommon($result)) { |
| | | $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | 'result class is not extended from MDB2_Result_Common', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | } |
| | | if ($result_wrap_class) { |
| | | if (!MDB2::classExists($result_wrap_class)) { |
| | | $err =& $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | 'result wrap class does not exist '.$result_wrap_class, __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | |
| | | $condition = ' WHERE '.implode(' AND ', $condition); |
| | | $query = 'DELETE FROM ' . $this->quoteIdentifier($table, true) . $condition; |
| | | $result =& $this->_doQuery($query, true, $connection); |
| | | $result = $this->_doQuery($query, true, $connection); |
| | | if (!PEAR::isError($result)) { |
| | | $affected_rows = $this->_affectedRows($connection, $result); |
| | | $insert = ''; |
| | |
| | | } |
| | | $values = implode(', ', $values); |
| | | $query = 'INSERT INTO '. $this->quoteIdentifier($table, true) . "($insert) VALUES ($values)"; |
| | | $result =& $this->_doQuery($query, true, $connection); |
| | | $result = $this->_doQuery($query, true, $connection); |
| | | if (!PEAR::isError($result)) { |
| | | $affected_rows += $this->_affectedRows($connection, $result);; |
| | | } |
| | |
| | | * @access public |
| | | * @see bindParam, execute |
| | | */ |
| | | function &prepare($query, $types = null, $result_types = null, $lobs = array()) |
| | | function prepare($query, $types = null, $result_types = null, $lobs = array()) |
| | | { |
| | | $is_manip = ($result_types === MDB2_PREPARE_MANIP); |
| | | $offset = $this->offset; |
| | |
| | | $regexp = '/^.{'.($position+1).'}('.$this->options['bindname_format'].').*$/s'; |
| | | $parameter = preg_replace($regexp, '\\1', $query); |
| | | if ($parameter === '') { |
| | | $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | 'named parameter name must match "bindname_format" option', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | */ |
| | | function _skipDelimitedStrings($query, $position, $p_position) |
| | | { |
| | | $ignores = $this->string_quoting; |
| | | $ignores = array(); |
| | | $ignores[] = $this->string_quoting; |
| | | $ignores[] = $this->identifier_quoting; |
| | | $ignores = array_merge($ignores, $this->sql_comments); |
| | | |
| | |
| | | if ($ignore['end'] === "\n") { |
| | | $end_quote = strlen($query) - 1; |
| | | } else { |
| | | $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | 'query with an unterminated text string specified', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | var $column_names; |
| | | |
| | | // }}} |
| | | // {{{ constructor: function __construct(&$db, &$result, $limit = 0, $offset = 0) |
| | | // {{{ constructor: function __construct($db, &$result, $limit = 0, $offset = 0) |
| | | |
| | | /** |
| | | * Constructor |
| | | */ |
| | | function __construct(&$db, &$result, $limit = 0, $offset = 0) |
| | | function __construct($db, &$result, $limit = 0, $offset = 0) |
| | | { |
| | | $this->db =& $db; |
| | | $this->result =& $result; |
| | | $this->db = $db; |
| | | $this->result = $result; |
| | | $this->offset = $offset; |
| | | $this->limit = max(0, $limit - 1); |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0) |
| | | |
| | | /** |
| | | * PHP 4 Constructor |
| | | */ |
| | | function MDB2_Result_Common(&$db, &$result, $limit = 0, $offset = 0) |
| | | { |
| | | $this->__construct($db, $result, $limit, $offset); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
| | | function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
| | | { |
| | | $err =& $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | $err = $this->db->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | 'method not implemented', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function MDB2_Row(&$row) |
| | | |
| | | /** |
| | | * PHP 4 Constructor |
| | | * |
| | | * @param resource row data as array |
| | | */ |
| | | function MDB2_Row(&$row) |
| | | { |
| | | $this->__construct($row); |
| | | } |
| | | |
| | | // }}} |
| | | } |
| | | |
| | | // }}} |
| | |
| | | var $is_manip; |
| | | |
| | | // }}} |
| | | // {{{ constructor: function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | // {{{ constructor: function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | |
| | | /** |
| | | * Constructor |
| | | */ |
| | | function __construct(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | function __construct($db, $statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | { |
| | | $this->db =& $db; |
| | | $this->statement =& $statement; |
| | | $this->db = $db; |
| | | $this->statement = $statement; |
| | | $this->positions = $positions; |
| | | $this->query = $query; |
| | | $this->types = (array)$types; |
| | |
| | | $this->limit = $limit; |
| | | $this->is_manip = $is_manip; |
| | | $this->offset = $offset; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | |
| | | /** |
| | | * PHP 4 Constructor |
| | | */ |
| | | function MDB2_Statement_Common(&$db, &$statement, $positions, $query, $types, $result_types, $is_manip = false, $limit = null, $offset = null) |
| | | { |
| | | $this->__construct($db, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset); |
| | | } |
| | | |
| | | // }}} |
| | |
| | | * a MDB2 error on failure |
| | | * @access public |
| | | */ |
| | | function &execute($values = null, $result_class = true, $result_wrap_class = false) |
| | | function execute($values = null, $result_class = true, $result_wrap_class = false) |
| | | { |
| | | if (null === $this->positions) { |
| | | return $this->db->raiseError(MDB2_ERROR, null, null, |
| | |
| | | 'Binding Values failed with message: ' . $err->getMessage(), __FUNCTION__); |
| | | } |
| | | } |
| | | $result =& $this->_execute($result_class, $result_wrap_class); |
| | | $result = $this->_execute($result_class, $result_wrap_class); |
| | | return $result; |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &_execute($result_class = true, $result_wrap_class = false) |
| | | // {{{ function _execute($result_class = true, $result_wrap_class = false) |
| | | |
| | | /** |
| | | * Execute a prepared query statement helper method. |
| | |
| | | * a MDB2 error on failure |
| | | * @access private |
| | | */ |
| | | function &_execute($result_class = true, $result_wrap_class = false) |
| | | function _execute($result_class = true, $result_wrap_class = false) |
| | | { |
| | | $this->last_query = $this->query; |
| | | $query = ''; |
| | |
| | | if ($this->is_manip) { |
| | | $result = $this->db->exec($query); |
| | | } else { |
| | | $result =& $this->db->query($query, $this->result_types, $result_class, $result_wrap_class); |
| | | $result = $this->db->query($query, $this->result_types, $result_class, $result_wrap_class); |
| | | } |
| | | return $result; |
| | | } |
| | |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function MDB2_Module_Common($db_index) |
| | | |
| | | /** |
| | | * PHP 4 Constructor |
| | | */ |
| | | function MDB2_Module_Common($db_index) |
| | | { |
| | | $this->__construct($db_index); |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ function &getDBInstance() |
| | | // {{{ function getDBInstance() |
| | | |
| | | /** |
| | | * Get the instance of MDB2 associated with the module instance |
| | |
| | | * |
| | | * @access public |
| | | */ |
| | | function &getDBInstance() |
| | | function getDBInstance() |
| | | { |
| | | if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) { |
| | | $result =& $GLOBALS['_MDB2_databases'][$this->db_index]; |
| | | $result = $GLOBALS['_MDB2_databases'][$this->db_index]; |
| | | } else { |
| | | $result =& MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | $result = MDB2::raiseError(MDB2_ERROR_NOT_FOUND, null, null, |
| | | 'could not find MDB2 instance'); |
| | | } |
| | | return $result; |