cvs: pear /MDB2 MDB2.php
| From: | Lukas Smith | Date: | Thu, 09 Sep 2004 19:11:57 +0000 |
| Subject: | cvs: pear /MDB2 MDB2.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-23764@lists.php.net to get a copy of this message | ||
lsmith Thu Sep 9 15:11:57 2004 EDT
Modified files:
/pear/MDB2 MDB2.php
Log:
- ensure we are returning a reference
- reworked dsn default handling
- added ability to "xxx" out password in getDSN()
- "xxx" out password in MDB2::connect()
http://cvs.php.net/diff.php/pear/MDB2/MDB2.php?r1=1.40&r2=1.41&ty=u
Index: pear/MDB2/MDB2.php
diff -u pear/MDB2/MDB2.php:1.40 pear/MDB2/MDB2.php:1.41
--- pear/MDB2/MDB2.php:1.40 Thu Sep 9 10:11:49 2004
+++ pear/MDB2/MDB2.php Thu Sep 9 15:11:56 2004
@@ -43,7 +43,7 @@
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2.php,v 1.40 2004/09/09 14:11:49 lsmith Exp $
+// $Id: MDB2.php,v 1.41 2004/09/09 19:11:56 lsmith Exp $
//
/**
@@ -207,8 +207,20 @@
* These are global variables that are used to track the various class instances
*/
-$GLOBALS['_MDB2_LOBs'] = array();
$GLOBALS['_MDB2_databases'] = array();
+$GLOBALS['_MDB2_LOBs'] = array();
+$GLOBALS['_MDB2_dsninfo_default'] = array(
+ 'phptype' => false,
+ 'dbsyntax' => false,
+ 'username' => false,
+ 'password' => false,
+ 'protocol' => false,
+ 'hostspec' => false,
+ 'port' => false,
+ 'socket' => false,
+ 'database' => false,
+ 'mode' => false,
+);
/**
* The main 'MDB2' class is simply a container class with some static
@@ -353,7 +365,7 @@
if (isset($dsninfo['database'])) {
$err = $db->connect();
if (MDB2::isError($err)) {
- $dsn = $db->getDSN();
+ $dsn = $db->getDSN('string', 'xxx');
$db->disconnect();
$err->addUserInfo($dsn);
return $err;
@@ -396,19 +408,7 @@
{
if ($dsn) {
$dsninfo = MDB2::parseDSN($dsn);
- $dsninfo_default = array(
- 'phptype' => false,
- 'dbsyntax' => false,
- 'username' => false,
- 'password' => false,
- 'protocol' => false,
- 'hostspec' => false,
- 'port' => false,
- 'socket' => false,
- 'database' => false,
- 'mode' => false,
- );
- $dsninfo = array_merge($dsninfo_default, $dsninfo);
+ $dsninfo = array_merge($GLOBALS['_MDB2_dsninfo_default'], $dsninfo);
$keys = array_keys($GLOBALS['_MDB2_databases']);
for ($i=0, $j=count($keys); $i<$j; ++$i) {
$tmp_dsn =
$GLOBALS['_MDB2_databases'][$keys[$i]]->getDSN('array');
@@ -649,18 +649,7 @@
*/
function parseDSN($dsn)
{
- $parsed = array(
- 'phptype' => false,
- 'dbsyntax' => false,
- 'username' => false,
- 'password' => false,
- 'protocol' => false,
- 'hostspec' => false,
- 'port' => false,
- 'socket' => false,
- 'database' => false,
- 'mode' => false,
- );
+ $parsed = $GLOBALS['_MDB2_dsninfo_default'];
if (is_array($dsn)) {
$dsn = array_merge($parsed, $dsn);
@@ -1589,17 +1578,7 @@
*/
function setDSN($dsn)
{
- $dsn_default = array (
- 'phptype' => false,
- 'dbsyntax' => false,
- 'username' => false,
- 'password' => false,
- 'protocol' => false,
- 'hostspec' => false,
- 'port' => false,
- 'socket' => false,
- 'mode' => false,
- );
+ $dsn_default = $GLOBALS['_MDB2_dsninfo_default'];
$dsn = MDB2::parseDSN($dsn);
if (isset($dsn['database'])) {
$this->database_name = $dsn['database'];
@@ -1616,24 +1595,18 @@
* return the DSN as a string
*
* @param string $type type to return
+ * @param string $hidepw string to hide the password with
* @return mixed DSN in the chosen type
* @access public
*/
- function getDSN($type = 'string')
+ function getDSN($type = 'string', $hidepw = false)
{
- $dsn_default = array (
- 'phptype' => $this->phptype,
- 'dbsyntax' => false,
- 'username' => false,
- 'password' => false,
- 'protocol' => false,
- 'hostspec' => false,
- 'port' => false,
- 'socket' => false,
- 'database' => $this->database_name,
- 'mode' => false,
- );
- $dsn = array_merge($dsn_default, $this->dsn);
+ $dsn = array_merge($GLOBALS['_MDB2_dsninfo_default'], $this->dsn);
+ $dsn['phptype'] = $this->phptype;
+ $dsn['database'] = $this->database_name;
+ if ($hidepw) {
+ $dsn['password'] = $hidepw;
+ }
switch ($type) {
// expand to include all possible options
case 'string':
@@ -1713,7 +1686,7 @@
* @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
* @access private
*/
- function _wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class, $offset,
$limit)
+ function &_wrapResult($result, $ismanip, $types, $result_class, $result_wrap_class,
$offset, $limit)
{
if (!$ismanip) {
if (!$result_class) {
@@ -1791,7 +1764,7 @@
*/
function subSelect($query, $type = false)
{
- if ($this->supported['sub_selects'] == true) {
+ if ($this->supported['sub_selects']) {
return $query;
}
return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null,
@@ -1946,7 +1919,7 @@
* @access public
* @see execute
*/
- function prepare($query, $types = null, $result_types = null)
+ function &prepare($query, $types = null, $result_types = null)
{
$this->debug($query, 'prepare');
$positions = array();
@@ -2053,10 +2026,7 @@
if (MDB2::isError($result)) {
return $result;
}
- if (method_exists($this->datatype, "get{$type}Declaration")) {
- return $this->datatype->{"get{$type}Declaration"}($name, $field);
- }
- return $this->raiseError('type not defined: '.$type);
+ return $this->datatype->getDeclaration($type, $name, $field);
}
// }}}