By Greg

2012-04-03 03:44:26 8 Comments

I've never used php before and am trying to connect to a SQL Server 2008 instance on a Windows machine running IIS7 and PHP5.3.

I have downloaded and installed SQLSRV30.EXE from here in C:\Program Files (x86)\PHP\ext added this to C:\Program Files (x86)\PHP\php.ini:


Then restarted the entire server. I still get fatal errors in my log file saying:

PHP Fatal error:  Call to undefined function mssql_connect()

What do I need to do to connect to Microsoft SQL Server 2008 from PHP 5.3 running on IIS7/Windows Server 2008? I'm sure it's something really dumb that I'm missing...



PHP Version 5.3.10


Windows NT MWD001 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 

Build Date 

Feb 2 2012 20:10:58 


MSVC9 (Visual C++ 2008) 



Configure Command 

cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet" "--with-mcrypt=static" "--disable-static-analyze" 

Server API 


Virtual Directory Support 


Configuration File (php.ini) Path 


Loaded Configuration File 

C:\Program Files (x86)\PHP\php.ini 


@M Shiraz Baig 2014-07-19 09:15:10

I am using IIS and mysql (directly downloaded, without wamp or xampp) My php was installed in c:\php I was getting the error of "call to undefined function mysql_connect()" For me the change of extension_dir worked. This is what I did. In the php.ini, Originally, I had this line

; On windows: extension_dir = "ext"

I changed it to:

; On windows: extension_dir = "C:\php\ext"

And it worked. Of course, I did the other things also like uncommenting the dll extensions etc, as explained in others remarks.

@Chris K 2012-04-03 03:56:12

php.ini probably needs to read: extension=ext\php_sqlsrv_53_nts.dll

Or move the file to same directory as the php executable. This is what I did to my php5 install this week to get odbc_pdo working. :P

Additionally, that doesn't look like proper phpinfo() output. If you make a file with contents
<? phpinfo(); ?> and visit that page, the HTML output should show several sections, including one with loaded modules. (Edited to add: like shown in the screenshot of the above accepted answer)

@Greg 2012-04-03 04:05:58

Sorry, here's the full phpinfo()

@F21 2012-04-03 03:59:38

I have just tried to install that extension on my dev server.

First, make sure that the extension is correctly enabled. Your phpinfo() output doesn't seem complete.

If it is indeed installed properly, your phpinfo() should have a section that looks like this: enter image description here

If you do not get that section in your phpinfo(). Make sure that you are using the right version. There are both non-thread-safe and thread-safe versions of the extension.

Finally, check your extension_dir setting. By default it's this: extension_dir = "ext", for most of the time it works fine, but if it doesn't try: extension_dir = "C:\PHP\ext".


EDIT given new info:

You are using the wrong function. mssql_connect() is part of the Mssql extension. You are using microsoft's extension, so use sqlsrv_connect(), for the API for the microsoft driver, look at SQLSRV_Help.chm which should be extracted to your ext directory when you extracted the extension.

@Greg 2012-04-03 04:04:21

Sorry, here's the full phpinfo(), I do have the sqlsrv section

@Chris K 2012-04-03 04:09:55

Yes, I was about to say I didn't see a mssql section in the phpinfo.

@Greg 2012-04-03 04:23:01

yay.. I'm in :), I had to download SQL Server 2012 Native Client

@shaiss 2013-02-11 13:30:40

Thank you! I had been using mssql_connect() till this post turned on the bulb. I opened the chm and am using sqlsrv_connect() with no problems. Thank You!

Related Questions

Sponsored Content

33 Answered Questions

[SOLVED] startsWith() and endsWith() functions in PHP

  • 2009-05-07 12:14:27
  • Click Upvote
  • 848069 View
  • 1491 Score
  • 33 Answer
  • Tags:   php string

30 Answered Questions

[SOLVED] How do I get PHP errors to display?

18 Answered Questions

13 Answered Questions

[SOLVED] Why shouldn't I use mysql_* functions in PHP?

  • 2012-10-12 13:18:39
  • Madara's Ghost
  • 222592 View
  • 2511 Score
  • 13 Answer
  • Tags:   php mysql

1 Answered Questions

[SOLVED] The sqlsrv PHP extension is not loaded properly or available for PHP to use

  • 2016-05-12 22:35:35
  • eat-sleep-code
  • 907 View
  • 2 Score
  • 1 Answer
  • Tags:   php sql

1 Answered Questions

php_mssql.dll not loading in PHP.ini

  • 2016-05-10 16:48:44
  • ShorePatrol
  • 1413 View
  • 0 Score
  • 1 Answer
  • Tags:   php sql-server iis-8

2 Answered Questions

[SOLVED] PHP error reporting will not turn off

1 Answered Questions

1 Answered Questions

[SOLVED] PHP Configuration file won’t load IIS7 x64

  • 2009-05-22 20:15:59
  • Nathan Stott
  • 1347 View
  • 3 Score
  • 1 Answer
  • Tags:   php iis-7 fastcgi

Sponsored Content