Author Topic: Can't get MSSQL to work with PHP.  (Read 1396 times)

0 Members and 1 Guest are viewing this topic.

Offline ColinPTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Can't get MSSQL to work with PHP.
« on: March 18, 2010, 11:42:10 AM »
Hello,

I'm setting up PHP on a server that's been working with ASP and MSSQL (I usually work with *nix environments). I installed PHP using the installer from the website. I checked the 'MSSQL' extention in the installer to make sure it installed that too.

php_mssql.dll is in the ext folder
PHP.ini is in /Windows/
php_mssql.dll is added as an extention in the loaded PHP.ini file.

phpinfo(); confirms that php.ini is loading from the right place.

Here's the configure line from phpinfo if that helps:
Quote
cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\template" "--with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared" "--without-pi3web" "--enable-mongo=shared"

There's no sign of the word "mssql" in the phpinfo()

I found out that a DLL 'ntwdblib.dll' was needed in the windows path. It wasn't there, or anywhere else on the system, so I put it in /Windows/, /Windows/system32/ , and the PHP path (/Program Files/PHP5 & /ext)  for safe measure. Rebooted the server and web server, still no luck.

PHP is working fine apart from this.

The following code:
if (function_exists('mssql_connect')) {
  echo 
"function exists";
} else {
  echo 
"function doesn't exit.";
}

outputs
Code: [Select]
function doesn't exit.and this code:
$link mssql_connect($hostname$db_username$db_password);
returns
Code: [Select]
PHP Fatal error:  Call to undefined function mssql_connect() in C:\inetpub\wwwroot\db_open.php on line 7
Any help would be greatly appreciated as I am well and truely stumped.

Offline ColinPTopic starter

  • Irregular
  • Posts: 2
    • View Profile
Re: Can't get MSSQL to work with PHP.
« Reply #1 on: March 18, 2010, 01:24:00 PM »
I've found a bit of a work around so this is sort of resolved.

I downloaded the Microsoft SQL Server Driver for PHP (quick google seach will find the .dll in an executable with further instructions), placed it in the extensions directory and added it to php.ini.

After restarting the web server, I'm now able to use sqlsrv_ functions (such as sqlsrv_connect();) - they're not the same syntax as mssql_connect etc however, so you can't just plug and play this into an old application. mssql_ functions are still not working - but at least I can connect to MSSQL through PHP now.