Good day!

After connecting my php to sql server 2005 using the mssql_connect() syntax, which did not work. I try my best that I can to work it, but at the end I could not fix the error. So now, I try another option like I used Microsoft Driver for SQL Server and the syntax that Iโ€™m using is sqlsrv_connect()

Here are some configurations that I do to work the connection

  1. I put the php folder in in C:\
  2. I configure my IIS 6.0 to run php using isapi
  3. I installed the SQLSRV20.EXE inC:\php\ext
  4. I configure my php.ini
    I uncommented the ff:
    extension_dir = "./ext"
    cgi.force_redirect = 0
    doc_root = "C:\Inetpub\wwwroot"
    I add extension=php_sqlsrv_53_ts_vc9.dll

I create a php file to test the connection

<?php
$server = "ISM\SQLEXPRESS";
$connectOptions = array("Database" => "dbtest");
//Because UID and PWD are not specified in the connection option
//The connection is made with Windows Authentication.
if($conn)
{
echo "Connection established";
}
else
{
echo "Connection could not be established";
}
?>

After I run this code I got an error like this:

Fatal error: Call to undefined function sqlsrv_connect() in C:\Inetpub\wwwroot\testconn.php on line 5

I donโ€™t know where is the problem and how can I fix it.

I need to fix it as soon as possible, because almost 3 weeks I troubleshoot this connection.

Any help is highly appreciated
Thank you in advance.

    I have been doing a fair bit of work recently with IIS/PHP. Firstly it sounds like the sqlsrv extension isn't installed. Use a phpinfo() file to check.

    Second: Specify the username and password unless you have configured all your IIS and MSSQL windows permissions to allow IIS/PHP to have permission to authenticate with MSSQL via windows authentication. If you haven't done this enable SQL Server Authentication on MSSQL and enter the username and password into the connect function.

    Also take a look at the PDO SQLSRV driver for an object oriented approach.

      Use an absolute path for extension_dir (e.g. "C:\php\ext") rather than a relative one.

      Also, have you verified that the php.ini file you're editing is being read by PHP? Do a phpinfo(), note the value of one of the directives (e.g. display_errors), change its value in php.ini, restart IIS, and then verify that the change has been reflected in the phpinfo() readout.

        knowj;10965288 wrote:

        I have been doing a fair bit of work recently with IIS/PHP. Firstly it sounds like the sqlsrv extension isn't installed. Use a phpinfo() file to check.

        Second: Specify the username and password unless you have configured all your IIS and MSSQL windows permissions to allow IIS/PHP to have permission to authenticate with MSSQL via windows authentication. If you haven't done this enable SQL Server Authentication on MSSQL and enter the username and password into the connect function.

        Also take a look at the PDO SQLSRV driver for an object oriented approach.

        I installed already the sqlsrv and the location of the dll files is in the ext folder.wHERE i can see if the extension is in the php info(),because I can't see dll files in my phpinfo()๐Ÿ˜•

        How can I configured in my IIs thAt it is Windows Authentication.?My MSSQL is realy need to be a windows authentication.I also have pdosqlsrv in my ext folder becasue it is part of the sqlsrv installer.

          bradgrafelman;10965297 wrote:

          Use an absolute path for extension_dir (e.g. "C:\php\ext") rather than a relative one.

          Also, have you verified that the php.ini file you're editing is being read by PHP? Do a phpinfo(), note the value of one of the directives (e.g. display_errors), change its value in php.ini, restart IIS, and then verify that the change has been reflected in the phpinfo() readout.

          I change the extension_dir and I also on the display_errors and I restarted my IIS and i run my phpinfo() and I see that the display_errors is On,so the changes was take effect. But why is the doc_root has no value,but in my php.ini it has a value like this: "C:\Inetpub\wwwroot" and also the extension_dir the value in phpinfo() is php5,but in my php.ini I put it as "C:\php\ext".๐Ÿ˜•

            Write a Reply...