From 0748c693ffa9a69d3bf1b25e5ba1d309f1c56c1f Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 19 May 2010 15:36:56 +0200 Subject: [PATCH] DibiMsSql2005Driver: added config aliases 'username', 'password', 'database' --- dibi/drivers/mssql2005.php | 12 ++++++++---- examples/connect.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dibi/drivers/mssql2005.php b/dibi/drivers/mssql2005.php index 58883d3..d540d6b 100644 --- a/dibi/drivers/mssql2005.php +++ b/dibi/drivers/mssql2005.php @@ -16,6 +16,9 @@ * * Connection options: * - 'host' - the MS SQL server host name. It can also include a port number (hostname:port) + * - 'username' + * - 'password' + * - 'database' - the database name to select * - 'options' - connection info array {@link http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx} * - 'lazy' - if TRUE, connection will be established only when required * - 'charset' - character encoding to set (default is UTF-8) @@ -53,14 +56,15 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver */ public function connect(array &$config) { + DibiConnection::alias($config, 'options|UID', 'username'); + DibiConnection::alias($config, 'options|PWD', 'password'); + DibiConnection::alias($config, 'options|Database', 'database'); + if (isset($config['resource'])) { $this->connection = $config['resource']; - } elseif (isset($config['options'])) { - $this->connection = sqlsrv_connect($config['host'], (array) $config['options']); - } else { - $this->connection = sqlsrv_connect($config['host']); + $this->connection = sqlsrv_connect($config['host'], (array) $config['options']); } if (!is_resource($this->connection)) { diff --git a/examples/connect.php b/examples/connect.php index 2e182ae..799067b 100644 --- a/examples/connect.php +++ b/examples/connect.php @@ -128,6 +128,25 @@ echo "

\n"; +// connects to MS SQL 2005 +echo '

Connecting to MS SQL 2005: '; +try { + dibi::connect(array( + 'driver' => 'mssql2005', + 'host' => '(local)', + 'username' => 'Administrator', + 'password' => 'xxx', + 'database' => 'main', + )); + echo 'OK'; + +} catch (DibiException $e) { + echo get_class($e), ': ', $e->getMessage(), "\n"; +} +echo "

\n"; + + + // connects to Oracle echo '

Connecting to Oracle: '; try {