5,7 → 5,7 |
/** |
* Contains the DB_common base class |
* |
* PHP versions 4 and 5 |
* PHP version 5 |
* |
* 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: |
18,9 → 18,9 |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V.V. Cox <cox@idecnet.com> |
* @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 |
* @version CVS: $Id: common.php,v 1.137 2005/04/07 14:27:35 danielc Exp $ |
* @version CVS: $Id$ |
* @link http://pear.php.net/package/DB |
*/ |
|
40,9 → 40,9 |
* @author Stig Bakken <ssb@php.net> |
* @author Tomas V.V. Cox <cox@idecnet.com> |
* @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 |
* @version Release: 1.7.6 |
* @version Release: 1.9.2 |
* @link http://pear.php.net/package/DB |
*/ |
class DB_common extends PEAR |
121,7 → 121,22 |
*/ |
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 |
|
130,7 → 145,7 |
* |
* @return void |
*/ |
function DB_common() |
function __construct() |
{ |
$this->PEAR('DB_Error'); |
} |
189,7 → 204,7 |
function __wakeup() |
{ |
if ($this->was_connected) { |
$this->connect($this->dsn, $this->options); |
$this->connect($this->dsn, $this->options['persistent']); |
} |
} |
|
246,7 → 261,7 |
*/ |
function quoteString($string) |
{ |
$string = $this->quote($string); |
$string = $this->quoteSmart($string); |
if ($string{0} == "'") { |
return substr($string, 1, -1); |
} |
269,8 → 284,7 |
*/ |
function quote($string = null) |
{ |
return ($string === null) ? 'NULL' |
: "'" . str_replace("'", "''", $string) . "'"; |
return $this->quoteSmart($string); |
} |
|
// }}} |
424,18 → 438,57 |
*/ |
function quoteSmart($in) |
{ |
if (is_int($in) || is_double($in)) { |
if (is_int($in)) { |
return $in; |
} elseif (is_float($in)) { |
return $this->quoteFloat($in); |
} elseif (is_bool($in)) { |
return $in ? 1 : 0; |
return $this->quoteBoolean($in); |
} elseif (is_null($in)) { |
return 'NULL'; |
} else { |
if ($this->dbsyntax == 'access' |
&& preg_match('/^#.+#$/', $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() |
|
/** |
837,7 → 890,7 |
if (DB::isError($sth)) { |
return $sth; |
} |
$ret =& $this->execute($sth, array_values($fields_values)); |
$ret = $this->execute($sth, array_values($fields_values)); |
$this->freePrepared($sth); |
return $ret; |
|
931,7 → 984,7 |
* "'it''s good'", |
* 'filename.txt' |
* ); |
* $res =& $db->execute($sth, $data); |
* $res = $db->execute($sth, $data); |
* </code> |
* |
* @param resource $stmt a DB statement resource returned from prepare() |
960,7 → 1013,7 |
if ($result === DB_OK || DB::isError($result)) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
return $tmp; |
} |
} |
1041,7 → 1094,7 |
function executeMultiple($stmt, $data) |
{ |
foreach ($data as $value) { |
$res =& $this->execute($stmt, $value); |
$res = $this->execute($stmt, $value); |
if (DB::isError($res)) { |
return $res; |
} |
1154,7 → 1207,7 |
if (DB::isError($sth)) { |
return $sth; |
} |
$ret =& $this->execute($sth, $params); |
$ret = $this->execute($sth, $params); |
$this->freePrepared($sth, false); |
return $ret; |
} else { |
1163,7 → 1216,7 |
if ($result === DB_OK || DB::isError($result)) { |
return $result; |
} else { |
$tmp =& new DB_result($this, $result); |
$tmp = new DB_result($this, $result); |
return $tmp; |
} |
} |
1194,8 → 1247,8 |
if (DB::isError($query)){ |
return $query; |
} |
$result =& $this->query($query, $params); |
if (is_a($result, 'DB_result')) { |
$result = $this->query($query, $params); |
if (is_object($result) && is_a($result, 'DB_result')) { |
$result->setOption('limit_from', $from); |
$result->setOption('limit_count', $count); |
} |
1229,10 → 1282,10 |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
$res = $this->query($query); |
} |
|
if (DB::isError($res)) { |
1293,10 → 1346,10 |
if (DB::isError($sth)) { |
return $sth; |
} |
$res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
$res = $this->query($query); |
} |
|
if (DB::isError($res)) { |
1344,10 → 1397,10 |
return $sth; |
} |
|
$res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
$res = $this->query($query); |
} |
|
if (DB::isError($res)) { |
1360,7 → 1413,7 |
$ret = array(); |
} else { |
if (!array_key_exists($col, $row)) { |
$ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); |
$ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); |
} else { |
$ret = array($row[$col]); |
while (is_array($row = $res->fetchRow($fetchmode))) { |
1476,10 → 1529,10 |
return $sth; |
} |
|
$res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
$res = $this->query($query); |
} |
|
if (DB::isError($res)) { |
1491,7 → 1544,7 |
$cols = $res->numCols(); |
|
if ($cols < 2) { |
$tmp =& $this->raiseError(DB_ERROR_TRUNCATED); |
$tmp = $this->raiseError(DB_ERROR_TRUNCATED); |
return $tmp; |
} |
|
1603,10 → 1656,10 |
return $sth; |
} |
|
$res =& $this->execute($sth, $params); |
$res = $this->execute($sth, $params); |
$this->freePrepared($sth); |
} else { |
$res =& $this->query($query); |
$res = $this->query($query); |
} |
|
if ($res === DB_OK || DB::isError($res)) { |
1627,7 → 1680,7 |
$res->free(); |
|
if (DB::isError($row)) { |
$tmp =& $this->raiseError($row); |
$tmp = $this->raiseError($row); |
return $tmp; |
} |
return $results; |
1814,6 → 1867,10 |
* query and native error code. |
* @param mixed native error code, integer or string depending the |
* 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 |
* |
1820,7 → 1877,8 |
* @see PEAR_Error |
*/ |
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 |
if (is_object($code)) { |
2103,6 → 2161,52 |
} |
|
// }}} |
// {{{ 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() |
|
/** |