[unixODBC-support] unixODBC, php, adodb, DSNs and MSSQL

Rob Brandt bronto at csd-bes.net
Thu Aug 30 22:12:08 BST 2007


Newbie looking for help getting ODBC working.

I have written an application in php that accesses a hosted MSSQL 2000 
database over the internet.  I did development on a Windows PC and used 
the http://adodb.sourceforge.net/ package as a wrapper for cross 
database SQL queries.  Our goal is to eventually loosen MS's grip on us, 
but we aren't ready to move from MSSQL yet.  On my workstation, 
everything works great.  On the server, I cannot get a connection.

Getting this functioning on the Linux server (hosted) has been a chore. 
  We've resolved firewall issues, and have gotten unixODBC installed 
along with FreeTDS, isql and php-odbc.  php is version 5.2.3.

I have written the application using adodb's "dsn-less" approach, where 
the connection string contains what's usually in the dsn.  As I said, 
this works great on my PC.  My question is, is the DSN-less approach 
valid using unixODBC?  I am certainly willing to get one set up for 
purposes of testing and proving the connection.  I can also change the 
connection method in my application if that's what needs to be done.  I 
have tried setting up a DSN on the linux box, but when I try:

odbcinst -i -s -f tds.datasource.template -l
(logged in as user not root)

I get:

odbcinst: SQLWritePrivateProfileString failed with General error request 
failed.
odbcinst: SQLWritePrivateProfileString failed with General error request 
failed.

I don't understand the problem; seems like a permission error but no 
idea how to resolve it, and don't even know that I need a DSN.

Here's some sample dsn-less code from my app:

----------------------------
$db = bsa_mssql_connect();

$sql = "SELECT * FROM NewMembers WHERE USERPASSWORD LIKE '$password' AND 
((USERNAME LIKE '$username') OR (EMAIL LIKE '$username')) ";

$rs = $db->Execute($sql);
----------------------------
function bsa_mssql_connect() {
   	$DB = NewADOConnection('odbc_mssql');
	$dsn = "Driver={SQL Server};Server=xxx.xxx.xxx.xxx;Database=ourdbname;";
	$DB->SetFetchMode(ADODB_FETCH_ASSOC);
	$ok = $DB->Connect($dsn, 'userxxx', 'passxxx');
	
	if ($ok) {
		return $DB;
	} else {
		echo "no db connection";
	}
   }
------------------------------

Thanks in advance

Rob




More information about the unixODBC-support mailing list