cvs: php4 /pear DB.php /pear/DB/tests db_parsedsn.phpt

From: Date: Fri, 01 Feb 2002 15:03:18 +0000
Subject: cvs: php4 /pear DB.php /pear/DB/tests db_parsedsn.phpt
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-2272@lists.php.net to get a copy of this message
cox Fri Feb 1 10:03:18 2002 EDT Modified files: /php4/pear DB.php /php4/pear/DB/tests db_parsedsn.phpt Log: Added support for passing special backend params in DSN. Ex: ibase://user:pass@localhost/db?role=foo&dialect=bar Index: php4/pear/DB.php diff -u php4/pear/DB.php:1.83 php4/pear/DB.php:1.84 --- php4/pear/DB.php:1.83 Sat Jan 19 02:46:23 2002 +++ php4/pear/DB.php Fri Feb 1 10:03:17 2002 @@ -17,7 +17,7 @@ // | Tomas V.V.Cox <cox@idecnet.com> | // +----------------------------------------------------------------------+ // -// $Id: DB.php,v 1.83 2002/01/19 07:46:23 cox Exp $ +// $Id: DB.php,v 1.84 2002/02/01 15:03:17 cox Exp $ // // Database independent query interface. // @@ -520,7 +520,23 @@ // Get dabase if any // $dsn => database if (!empty($dsn)) { - $parsed['database'] = $dsn; + // /database + if (($pos = strpos($dsn, '?')) === false) { + $parsed['database'] = $dsn; + // /database?param1=value1&param2=value2 + } else { + $parsed['database'] = substr($dsn, 0, $pos); + $dsn = substr($dsn, $pos + 1); + if (strpos($dsn, '&') !== false) { + $opts = explode('&', $dsn); + } else { // database?param1=value1 + $opts = array($dsn); + } + foreach ($opts as $opt) { + list($key, $value) = explode('=', $opt); + $parsed[$key] = urldecode($value); + } + } } return $parsed; Index: php4/pear/DB/tests/db_parsedsn.phpt diff -u php4/pear/DB/tests/db_parsedsn.phpt:1.6 php4/pear/DB/tests/db_parsedsn.phpt:1.7 --- php4/pear/DB/tests/db_parsedsn.phpt:1.6 Sun Jan 13 14:27:27 2002 +++ php4/pear/DB/tests/db_parsedsn.phpt Fri Feb 1 10:03:18 2002 @@ -7,7 +7,7 @@ // Test for: DB::parseDSN() -require_once "DB.php"; +require_once "../../DB.php"; function test($dsn) { echo "DSN: $dsn\n"; @@ -36,6 +36,10 @@ test("pgsql://user@tcp()/pear"); test("pgsql://user@tcp(somehost)/pear"); test("pgsql://user:pass@word@tcp(somehost:7777)/pear"); + +// special backend options +test('ibase://user:pass@localhost//var/lib/dbase.dbf?role=foo'); +test('dbase://@/?role=foo&dialect=bar'); ?> --GET-- --POST-- @@ -275,4 +279,33 @@ [port] => 7777 [socket] => [database] => pear +) +DSN: ibase://user:pass@localhost//var/lib/dbase.dbf?role=foo +Array +( + [phptype] => ibase + [dbsyntax] => ibase + [username] => user + [password] => pass + [protocol] => tcp + [hostspec] => localhost + [port] => + [socket] => + [database] => /var/lib/dbase.dbf + [role] => foo +) +DSN: dbase://@/?role=foo&dialect=bar +Array +( + [phptype] => dbase + [dbsyntax] => dbase + [username] => + [password] => + [protocol] => tcp + [hostspec] => + [port] => + [socket] => + [database] => + [role] => foo + [dialect] => bar )

« previous php.pear.cvs (#2272) next »