1
0
mirror of https://github.com/dg/dibi.git synced 2025-03-13 19:00:05 +01:00

DibiMsSql2005Driver: added config aliases 'username', 'password', 'database'

This commit is contained in:
David Grudl 2010-05-19 15:36:56 +02:00
parent 550c477797
commit 0748c693ff
2 changed files with 27 additions and 4 deletions

View File

@ -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)) {

View File

@ -128,6 +128,25 @@ echo "</p>\n";
// connects to MS SQL 2005
echo '<p>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 "</p>\n";
// connects to Oracle
echo '<p>Connecting to Oracle: ';
try {