From 5ca4f396f8ea5955fb4ad5bba929f6cb40cd1d2b Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Tue, 16 Mar 2010 09:57:56 +1300 Subject: [PATCH] Allow SetConnection to be called with a DSN + options. --- inc/AwlQuery.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/inc/AwlQuery.php b/inc/AwlQuery.php index a9ab5d39..f54acc1a 100644 --- a/inc/AwlQuery.php +++ b/inc/AwlQuery.php @@ -253,12 +253,35 @@ class AwlQuery * Use a different database connection for this query * @param resource $new_connection The database connection to use. */ - function SetConnection( $new_connection ) { + function SetConnection( $new_connection, $options = null ) { + if ( is_string($new_connection) ) { + $dbuser = null; + $dbpass = null; + if ( is_array($v) ) { + $dsn = $v['dsn']; + if ( isset($v['dbuser']) ) $dbuser = $v['dbuser']; + if ( isset($v['dbpass']) ) $dbpass = $v['dbpass']; + } + elseif ( preg_match( '/^(\S+:)?(.*)( user=(\S+))?( password=(\S+))?$/', $v, $matches ) ) { + $dsn = $matches[2]; + if ( isset($matches[1]) && $matches[1] != '' ) { + $dsn = $matches[1] . $dsn; + } + else { + $dsn = 'pgsql:' . $dsn; + } + if ( isset($matches[4]) && $matches[4] != '' ) $dbuser = $matches[4]; + if ( isset($matches[6]) && $matches[6] != '' ) $dbpass = $matches[6]; + } + if ( $new_connection = new AwlDatabase( $dsn, $dbuser, $dbpass, $options ) ) break; + } $this->connection = $new_connection; + return $new_connection; } + /** * Log query, optionally with file and line location of the caller. *