| version 1.2, 2005/11/07 20:37:24 |
version 1.3, 2011/06/17 13:56:38 |
|
|
| * @author Stig Bakken <ssb@php.net> |
* @author Stig Bakken <ssb@php.net> |
| * @author Tomas V.V. Cox <cox@idecnet.com> |
* @author Tomas V.V. Cox <cox@idecnet.com> |
| * @author Daniel Convissor <danielc@php.net> |
* @author Daniel Convissor <danielc@php.net> |
| * @copyright 1997-2005 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 CVS: $Id$ |
* @version CVS: $Id$ |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| Line 40 require_once 'PEAR.php'; |
|
| Line 40 require_once 'PEAR.php'; |
|
| * @author Stig Bakken <ssb@php.net> |
* @author Stig Bakken <ssb@php.net> |
| * @author Tomas V.V. Cox <cox@idecnet.com> |
* @author Tomas V.V. Cox <cox@idecnet.com> |
| * @author Daniel Convissor <danielc@php.net> |
* @author Daniel Convissor <danielc@php.net> |
| * @copyright 1997-2005 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.6 |
* @version Release: 1.7.14RC2 |
| * @link http://pear.php.net/package/DB |
* @link http://pear.php.net/package/DB |
| */ |
*/ |
| class DB_common extends PEAR |
class DB_common extends PEAR |
| Line 121 class DB_common extends PEAR |
|
| Line 121 class DB_common extends PEAR |
|
| */ |
*/ |
| var $prepared_queries = array(); |
var $prepared_queries = array(); |
| |
|
| |
/** |
| |
* Flag indicating that the last query was a manipulation query. |
| |
* @access protected |
| |
* @var boolean |
| |
*/ |
| |
var $_last_query_manip = false; |
| |
|
| |
/** |
| |
* Flag indicating that the next query <em>must</em> be a manipulation |
| |
* query. |
| |
* @access protected |
| |
* @var boolean |
| |
*/ |
| |
var $_next_query_manip = false; |
| |
|
| |
|
| // }}} |
// }}} |
| // {{{ DB_common |
// {{{ DB_common |
| Line 189 class DB_common extends PEAR |
|
| Line 204 class DB_common extends PEAR |
|
| function __wakeup() |
function __wakeup() |
| { |
{ |
| if ($this->was_connected) { |
if ($this->was_connected) { |
| $this->connect($this->dsn, $this->options); |
$this->connect($this->dsn, $this->options['persistent']); |
| } |
} |
| } |
} |
| |
|
| Line 424 class DB_common extends PEAR |
|
| Line 439 class DB_common extends PEAR |
|
| */ |
*/ |
| function quoteSmart($in) |
function quoteSmart($in) |
| { |
{ |
| if (is_int($in) || is_double($in)) { |
if (is_int($in)) { |
| return $in; |
return $in; |
| |
} elseif (is_float($in)) { |
| |
return $this->quoteFloat($in); |
| } elseif (is_bool($in)) { |
} elseif (is_bool($in)) { |
| return $in ? 1 : 0; |
return $this->quoteBoolean($in); |
| } elseif (is_null($in)) { |
} elseif (is_null($in)) { |
| return 'NULL'; |
return 'NULL'; |
| } else { |
} else { |
| |
if ($this->dbsyntax == 'access' |
| |
&& preg_match('/^#.+#$/', $in)) |
| |
{ |
| |
return $this->escapeSimple($in); |
| |
} |
| return "'" . $this->escapeSimple($in) . "'"; |
return "'" . $this->escapeSimple($in) . "'"; |
| } |
} |
| } |
} |
| |
|
| // }}} |
// }}} |
| |
// {{{ quoteBoolean() |
| |
|
| |
/** |
| |
* Formats a boolean value for use within a query in a locale-independent |
| |
* manner. |
| |
* |
| |
* @param boolean the boolean value to be quoted. |
| |
* @return string the quoted string. |
| |
* @see DB_common::quoteSmart() |
| |
* @since Method available since release 1.7.8. |
| |
*/ |
| |
function quoteBoolean($boolean) { |
| |
return $boolean ? '1' : '0'; |
| |
} |
| |
|
| |
// }}} |
| |
// {{{ quoteFloat() |
| |
|
| |
/** |
| |
* Formats a float value for use within a query in a locale-independent |
| |
* manner. |
| |
* |
| |
* @param float the float value to be quoted. |
| |
* @return string the quoted string. |
| |
* @see DB_common::quoteSmart() |
| |
* @since Method available since release 1.7.8. |
| |
*/ |
| |
function quoteFloat($float) { |
| |
return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'"; |
| |
} |
| |
|
| |
// }}} |
| // {{{ escapeSimple() |
// {{{ escapeSimple() |
| |
|
| /** |
/** |
| Line 837 class DB_common extends PEAR |
|
| Line 891 class DB_common extends PEAR |
|
| if (DB::isError($sth)) { |
if (DB::isError($sth)) { |
| return $sth; |
return $sth; |
| } |
} |
| $ret =& $this->execute($sth, array_values($fields_values)); |
$ret = $this->execute($sth, array_values($fields_values)); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| return $ret; |
return $ret; |
| |
|
| Line 931 class DB_common extends PEAR |
|
| Line 985 class DB_common extends PEAR |
|
| * "'it''s good'", |
* "'it''s good'", |
| * 'filename.txt' |
* 'filename.txt' |
| * ); |
* ); |
| * $res =& $db->execute($sth, $data); |
* $res = $db->execute($sth, $data); |
| * </code> |
* </code> |
| * |
* |
| * @param resource $stmt a DB statement resource returned from prepare() |
* @param resource $stmt a DB statement resource returned from prepare() |
| Line 960 class DB_common extends PEAR |
|
| Line 1014 class DB_common extends PEAR |
|
| if ($result === DB_OK || DB::isError($result)) { |
if ($result === DB_OK || DB::isError($result)) { |
| return $result; |
return $result; |
| } else { |
} else { |
| $tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
| return $tmp; |
return $tmp; |
| } |
} |
| } |
} |
| Line 1041 class DB_common extends PEAR |
|
| Line 1095 class DB_common extends PEAR |
|
| function executeMultiple($stmt, $data) |
function executeMultiple($stmt, $data) |
| { |
{ |
| foreach ($data as $value) { |
foreach ($data as $value) { |
| $res =& $this->execute($stmt, $value); |
$res = $this->execute($stmt, $value); |
| if (DB::isError($res)) { |
if (DB::isError($res)) { |
| return $res; |
return $res; |
| } |
} |
| Line 1154 class DB_common extends PEAR |
|
| Line 1208 class DB_common extends PEAR |
|
| if (DB::isError($sth)) { |
if (DB::isError($sth)) { |
| return $sth; |
return $sth; |
| } |
} |
| $ret =& $this->execute($sth, $params); |
$ret = $this->execute($sth, $params); |
| $this->freePrepared($sth, false); |
$this->freePrepared($sth, false); |
| return $ret; |
return $ret; |
| } else { |
} else { |
| Line 1163 class DB_common extends PEAR |
|
| Line 1217 class DB_common extends PEAR |
|
| if ($result === DB_OK || DB::isError($result)) { |
if ($result === DB_OK || DB::isError($result)) { |
| return $result; |
return $result; |
| } else { |
} else { |
| $tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
| return $tmp; |
return $tmp; |
| } |
} |
| } |
} |
| Line 1194 class DB_common extends PEAR |
|
| Line 1248 class DB_common extends PEAR |
|
| if (DB::isError($query)){ |
if (DB::isError($query)){ |
| return $query; |
return $query; |
| } |
} |
| $result =& $this->query($query, $params); |
$result = $this->query($query, $params); |
| if (is_a($result, 'DB_result')) { |
if (is_a($result, 'DB_result')) { |
| $result->setOption('limit_from', $from); |
$result->setOption('limit_from', $from); |
| $result->setOption('limit_count', $count); |
$result->setOption('limit_count', $count); |
| Line 1229 class DB_common extends PEAR |
|
| Line 1283 class DB_common extends PEAR |
|
| if (DB::isError($sth)) { |
if (DB::isError($sth)) { |
| return $sth; |
return $sth; |
| } |
} |
| $res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| } else { |
} else { |
| $res =& $this->query($query); |
$res = $this->query($query); |
| } |
} |
| |
|
| if (DB::isError($res)) { |
if (DB::isError($res)) { |
| Line 1293 class DB_common extends PEAR |
|
| Line 1347 class DB_common extends PEAR |
|
| if (DB::isError($sth)) { |
if (DB::isError($sth)) { |
| return $sth; |
return $sth; |
| } |
} |
| $res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| } else { |
} else { |
| $res =& $this->query($query); |
$res = $this->query($query); |
| } |
} |
| |
|
| if (DB::isError($res)) { |
if (DB::isError($res)) { |
| Line 1344 class DB_common extends PEAR |
|
| Line 1398 class DB_common extends PEAR |
|
| return $sth; |
return $sth; |
| } |
} |
| |
|
| $res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| } else { |
} else { |
| $res =& $this->query($query); |
$res = $this->query($query); |
| } |
} |
| |
|
| if (DB::isError($res)) { |
if (DB::isError($res)) { |
| Line 1360 class DB_common extends PEAR |
|
| Line 1414 class DB_common extends PEAR |
|
| $ret = array(); |
$ret = array(); |
| } else { |
} else { |
| if (!array_key_exists($col, $row)) { |
if (!array_key_exists($col, $row)) { |
| $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); |
$ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); |
| } else { |
} else { |
| $ret = array($row[$col]); |
$ret = array($row[$col]); |
| while (is_array($row = $res->fetchRow($fetchmode))) { |
while (is_array($row = $res->fetchRow($fetchmode))) { |
| Line 1476 class DB_common extends PEAR |
|
| Line 1530 class DB_common extends PEAR |
|
| return $sth; |
return $sth; |
| } |
} |
| |
|
| $res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| } else { |
} else { |
| $res =& $this->query($query); |
$res = $this->query($query); |
| } |
} |
| |
|
| if (DB::isError($res)) { |
if (DB::isError($res)) { |
| Line 1491 class DB_common extends PEAR |
|
| Line 1545 class DB_common extends PEAR |
|
| $cols = $res->numCols(); |
$cols = $res->numCols(); |
| |
|
| if ($cols < 2) { |
if ($cols < 2) { |
| $tmp =& $this->raiseError(DB_ERROR_TRUNCATED); |
$tmp = $this->raiseError(DB_ERROR_TRUNCATED); |
| return $tmp; |
return $tmp; |
| } |
} |
| |
|
| Line 1603 class DB_common extends PEAR |
|
| Line 1657 class DB_common extends PEAR |
|
| return $sth; |
return $sth; |
| } |
} |
| |
|
| $res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
| $this->freePrepared($sth); |
$this->freePrepared($sth); |
| } else { |
} else { |
| $res =& $this->query($query); |
$res = $this->query($query); |
| } |
} |
| |
|
| if ($res === DB_OK || DB::isError($res)) { |
if ($res === DB_OK || DB::isError($res)) { |
| Line 1627 class DB_common extends PEAR |
|
| Line 1681 class DB_common extends PEAR |
|
| $res->free(); |
$res->free(); |
| |
|
| if (DB::isError($row)) { |
if (DB::isError($row)) { |
| $tmp =& $this->raiseError($row); |
$tmp = $this->raiseError($row); |
| return $tmp; |
return $tmp; |
| } |
} |
| return $results; |
return $results; |
| Line 1814 class DB_common extends PEAR |
|
| Line 1868 class DB_common extends PEAR |
|
| * query and native error code. |
* query and native error code. |
| * @param mixed native error code, integer or string depending the |
* @param mixed native error code, integer or string depending the |
| * backend |
* backend |
| |
* @param mixed dummy parameter for E_STRICT compatibility with |
| |
* PEAR::raiseError |
| |
* @param mixed dummy parameter for E_STRICT compatibility with |
| |
* PEAR::raiseError |
| * |
* |
| * @return object the PEAR_Error object |
* @return object the PEAR_Error object |
| * |
* |
| * @see PEAR_Error |
* @see PEAR_Error |
| */ |
*/ |
| function &raiseError($code = DB_ERROR, $mode = null, $options = null, |
function &raiseError($code = DB_ERROR, $mode = null, $options = null, |
| $userinfo = null, $nativecode = null) |
$userinfo = null, $nativecode = null, $dummy1 = null, |
| |
$dummy2 = null) |
| { |
{ |
| // The error is yet a DB error object |
// The error is yet a DB error object |
| if (is_object($code)) { |
if (is_object($code)) { |
| Line 2103 class DB_common extends PEAR |
|
| Line 2162 class DB_common extends PEAR |
|
| } |
} |
| |
|
| // }}} |
// }}} |
| |
// {{{ nextQueryIsManip() |
| |
|
| |
/** |
| |
* Sets (or unsets) a flag indicating that the next query will be a |
| |
* manipulation query, regardless of the usual DB::isManip() heuristics. |
| |
* |
| |
* @param boolean true to set the flag overriding the isManip() behaviour, |
| |
* false to clear it and fall back onto isManip() |
| |
* |
| |
* @return void |
| |
* |
| |
* @access public |
| |
*/ |
| |
function nextQueryIsManip($manip) |
| |
{ |
| |
$this->_next_query_manip = $manip; |
| |
} |
| |
|
| |
// }}} |
| |
// {{{ _checkManip() |
| |
|
| |
/** |
| |
* Checks if the given query is a manipulation query. This also takes into |
| |
* account the _next_query_manip flag and sets the _last_query_manip flag |
| |
* (and resets _next_query_manip) according to the result. |
| |
* |
| |
* @param string The query to check. |
| |
* |
| |
* @return boolean true if the query is a manipulation query, false |
| |
* otherwise |
| |
* |
| |
* @access protected |
| |
*/ |
| |
function _checkManip($query) |
| |
{ |
| |
if ($this->_next_query_manip || DB::isManip($query)) { |
| |
$this->_last_query_manip = true; |
| |
} else { |
| |
$this->_last_query_manip = false; |
| |
} |
| |
$this->_next_query_manip = false; |
| |
return $this->_last_query_manip; |
| |
$manip = $this->_next_query_manip; |
| |
} |
| |
|
| |
// }}} |
| // {{{ _rtrimArrayValues() |
// {{{ _rtrimArrayValues() |
| |
|
| /** |
/** |