[pmwiki-devel] Refactoring adodb-connect.php
marc
gmane at auxbuss.com
Wed Nov 29 09:05:50 CST 2006
Hi,
We were experiencing a slight delay with db connects using adodb-
connect.php, and while taking a look at it ended up with a new version:
<?php if (!defined('PmWiki')) exit();
SDV($ADOdbLocation, $_SERVER['DOCUMENT_ROOT'].'/adodb/');
function ADOdbConnect($dbName) {
global $ADOdbLocation, $Databases, $DB;
include_once $ADOdbLocation.'adodb.inc.php';
extract($Databases[$dbName]); # driver, hostname, database,
username, password
if (is_object($DB[$dbName])) {
if ($DB[$dbName]->IsConnected())
return true; }
switch ($driver) {
case 'access':
$DB[$dbName] = ADONewConnection('access');
$dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq="
.$database .";Uid=". $username .";Pwd=" .$password
.";";
$DB[$dbName]->Connect($dsn);
break;
case 'mssql':
case 'odbc_mssql':
$DB[$dbName] = ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=" .$hostname
.";Database=". $database .";";
$DB[$dbName]->Connect($dsn,$username,$password);
break;
case 'db2':
$DB[$dbName] = ADONewConnection('db2');
$dsn = "driver={IBM db2 odbc DRIVER};Database="
. $database .";hostname=". $hostname
. ";port=50000;protocol=TCPIP;uid=". $username . ";
pwd=" .$password;
$DB[$dbName]->Connect($dsn);
break;
default:
switch ($Databases[$dbName]['driver']) {
case 'pdo':
$driver = "pdo_mysql"; break;
case 'sqlite':
$database = urlencode($database); break;
}
$dsn = $driver .'://'
. ($username ? $username .':'. $password .'@' : '')
. ($hostname ? $hostname .'/' : '') . $database;
$DB[$dbName] = ADONewConnection($dsn);
}
if ((is_object($DB[$dbName])) and ($DB[$dbName]->IsConnected()))
return true;
else
return "Database not connected: ".$DB[$dbName]->ErrorMsg();
}
--
Best,
Marc
More information about the pmwiki-devel
mailing list