[clug-progsig] PEAR DB to connect to MS SQL Server?

Shawn sgrover at open2space.com
Thu Aug 18 23:21:24 PDT 2005


I'm trying to connect to a database on the Microsoft SQL Server, using php and 
PEAR DB.  But I keep getting a connection error.

Here's my function that establishes the connection:

function connect($host, $username, $pass, $dbname)
{
	$dsn = "mssql://$username:$pass@$host/$dbname";
	echo("\n\$dsn = $dsn");
	$tmpDB = DB::connect($dsn, true);
	
	//handle connection error
	if (DB::isError($tmpDB)) {
		die ("\n" . $tmpDB->getMessage() . "\n");
	}
	return $tmpDB;
}

Here's the output I'm getting from my program:

$dsn = mssql://myuser:userpass@192.168.0.16:1433/mydb
DB Error: connect failed

So, I've tried a couple of different things with the connection string, and 
I'm always getting the connect failed message. (i.e. tried host name, ip 
address, with/without the port number, etc.)  The rest of the connection 
string has correct information.

This is a PHP4 command line application running on Linux.  I noted the 
mssql_connect function requires the SQL Client tools to be installed - is 
this true for Pear DB as well?  If so, how can one connect to MSSQL from a 
linux box?

The obvious things have been checked - I do have mssql support compiled into 
PHP, and the database is running and accessible over the network.  (er, at 
least I can connect using Enterprise manager from my windows laptop...)

Any tips are appreciated.  I'm not especially familiar with Pear DB (yet), so 
could have made a mistake somewhere...  Thanks bunches.

Shawn



More information about the clug-progsig mailing list