Jump to content

[SOLVED] Can't get Microsoft SQL Server driver OR mssql to work


alexmetal

Recommended Posts

After a couple years of not writing any PHP, I've come back to it to make a time clock system for my company. Instead of installing MySQL, I decided to use our SQL server. It's SQL Server 2005 running on Windows Server 2003. PHP 5 and Apache 2.2.0 are installed on a Windows XP Pro SP3 machine. When trying to connect to the server (either using sqlsvr_connect() or mssql_connect(), I don't get anything. I don't get an error. Just a blank page. Any ideas?

 

Here's the code:

function sqlCon() {
$serv = "CSNSVR01\CSNSVR01";
$con_prop = array("UID"=>"user","PWD"=>"pass","DATABASE"=>"CSNTC");
$con = sqlsvr_connect($serv,$con_prop);
if (!$con) {
	die(print_r(sqlsrv_errors(),true));
}
echo "Connection successful.";
sqlsvr_close($con);
}

A blank page is either the result of a parse error or a fatal runtime error (or code that simply does not output anything.)

 

Have you checked your web server error log and/or turned on full php error reporting to see what errors are occurring?

I'm getting this in Apache: (didn't even think to look)

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mssql.dll' - The specified module could not be found.\r\n in Unknown on line 0

 

How should extension_dir: be configured in php.ini? I have is as "C:\php\ext\", isn't that right? I made sure php_mssql.dll is in the directory, too.

mssql requires an auxiliary .dll file called - ntwdblib.dll This file must be in a folder that is on the Windows PATH statement. This file is normally in the main php folder. The best way to get this and other extensions that use auxiliary .dll files to work is to add the main php folder to the Windows PATH statement (reboot your computer to get any change made to the Windows PATH statement to take effect.)

The final step is to add a registry key on the PHP server.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo (If the ConnectTo key doesn't exist, create it)

The create a new string value DSQUERY and put DBNETLIB for the data.

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.