phpLens
 home  products examples manual  faq support forum  contact news  login store

Forums: phplens   adodb
Forums:   ADOdb Help & Dev:   Replies 
New ReplySearch
Topic: Add Database Name when using _connnect
author: Graeme   created: 20-04-2012 09:28:43 AM
Hi,

When attempting to connect via ODBC I noticed that the Database Name variable was not being used. Instead you tell people in the Debug to place the Database Name into the Connection String.

However after a bit of tweaking I see no reason why you can't append it to the end of the Connection String in the _connect function.

The following patch simply checks to see if "Database=" doesn't exist already and the Database Name variable is set. It then goes to add a semi-colon to the end of the Connection String if needed. It then goes to append the Database Name.

Any comments welcome
--- C:/adodb516a-org/adodb5/drivers/adodb-odbc.inc.php Mon Mar 26 13:21:06 2012
+++ C:/adodb516a/adodb5/drivers/adodb-odbc.inc.php Fri Apr 20 14:57:28 2012
@@ -52,9 +52,24 @@

if (!function_exists('odbc_connect')) return null;

- if ($this->debug && $argDatabasename && $this->databaseType != 'vfp') {
- ADOConnection::outp("For odbc Connect(), $argDatabasename is not used. Place dsn in 1st parameter.");
+ $foundDatabaseName = !(stristr($argDSN,'Database=') === FALSE);
+
+ if ($this->debug && !empty($argDatabasename) && $foundDatabaseName) {
+ ADOConnection::outp("Databse name already found in 1st parameter, ignoring Database Name Parameter");
+ }
+
+ if(!empty($argDatabasename) && !$foundDatabaseName) {
+ // If Database Name is set, and not already in the DSN parameter then
+ // Check if DSN ends in a semi-colon
+ $dSN_end = substr($argDSN, strlen($argDSN) - 1);
+ if ($dSN_end != ';'){
+ // Add semi-colon to DSN if not alread there
+ $argDSN .= ';';
+ }
+ // Append Database Name to DSN
+ $argDSN .= 'Database='.$argDatabasename;
}
+
if (isset($php_errormsg)) $php_errormsg = '';
if ($this->curmode === false) $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword);
else $this->_connectionID = odbc_connect($argDSN,$argUsername,$argPassword,$this->curmode);
When connec
Topic: Re:Add Database Name when using _connnect
author: John Lim   created: 02-05-2012 00:05:54 AM
Hi, I have incorporated a similar fix for 5.17.

if (!function_exists('odbc_connect')) return null;

if (!empty($argDatabasename) && stristr($argDSN, 'Database=') === false) {
$argDSN = trim($argDSN);
$endDSN = substr($argDSN, strlen($argDSN) - 1);
if ($endDSN != ';') $argDSN .= ';';
$argDSN .= 'Database='.$argDatabasename;
}
Page 1
New ReplySearch

View Source

email: contact#phplens.com (change # to @)     telephone (malaysia): 60-3-7947 2888     fax (malaysia): 60-3-7947 2800