5

I went through several questions and recommendation to resolve the above issue, but No luck at all.

I have the following settings:

Windows Server 2008 R2

xenter image description hereampp-win32-1.8.2-5-VC9-installer

SQLSRV30 - php driver

sqlncli - Microsoft SQL Server 2008 R2 Native Client Set Up

I installed everything else and I have the following on the php.ini file The code below show where the php drivers are residing:

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

enter image description here The following is under windows extensions

extension=php_pdo_sqlsrv_54_ts.dll
extension=php_sqlsrv_54_ts.dll

enter image description here

When I check the phpinfo file sqlsrv is not listed. I know this may imply that its not installed, but It is installed.

The following is the php info file:

I also restarted apache and the server. Am I missing something ?

I get the following error:

Call to undefined function sqlsrv_connect()

This the code I am using to connect: I am connecting to another server which is hosting SQL Server 2005

/Connection to SQL Server Database
    error_reporting(E_ALL);
$serverName = "172.xx.x.xxx";

$connectionInfo = array('Database'=>'Eque', "UID"=>"develop", "PWD"=>"develop");
$conn = sqlsrv_connect($serverName, $connectionInfo);


if($conn) {
     echo "Connection established.<br />";
}else {
    echo  "Connection could not be established.<br />";
    die(print_r(sqlsrv_errors(), true));
}
Community
  • 1
  • 1
kya
  • 1,798
  • 8
  • 35
  • 61

3 Answers3

8

I have struggled through the process and this is what has finally worked. I am using php 5.4.16 and Apache 2.4.4 with Sql Express 2008 R2.

  1. Download Microsoft Drivers for PHP for SQL Server from Microsoft download site

  2. Extact the files to a local folder

  3. Copy php_sqlsrv_54_ts.dll and php_pdo_sqlsrv_54_ts.dll to the Ext folder (C:\wamp\bin\php\php5.4.16\ext). You can confirm the folder by checking the value of extension_dir in php.ini file stored under Apache (C:\wamp\bin\apache\Apache2.4.4\bin).
  4. Add extension for the two drivers by adding these lines: extension=php_sqlsrv_54_ts.dll extension=php_pdo_sqlsrv_54_ts.dll and comment out the existing lines below if not commented: ;extension=php_pdo_mssql.dll ;extension=php_mssql.dll
  5. Start all Wamp services
Isaac Gachugu
  • 149
  • 1
  • 5
4

Load the PHP drivers in php.ini file and restart the server.

extension=php_sqlsrv_53_ts.dll
extension=php_pdo_sqlsrv_53_ts.dll

Reference: http://technet.microsoft.com/en-us/library/cc296203(v=sql.105).aspx

TS denotes thread safe. find your server is thread safe or non thread safe

Sundar
  • 4,580
  • 6
  • 35
  • 61
  • I am using php 5.4.27. isn't the drivers you are recommending for php 5.3 ?. I attached the phpinfo file for more details – kya Jul 16 '14 at 08:57
  • This should work. Still they not released 5.4 anyway check it up again in the drivers folder.. what you pasted in the ext folder. if you 54 use that or use 53. 53 will work i used it before – Sundar Jul 16 '14 at 08:59
  • use this function to test your loaded extensions http://php.net/manual/en/function.extension-loaded.php – Sundar Jul 16 '14 at 09:01
  • Still no luck. Its not part of the loaded extensions – kya Jul 16 '14 at 12:14
  • check your apache error log and find your errors. And find your machine is thread safe or non thread safe. Check what are the sqlsrv files are exist in this folder C:\xampp\php\ext – Sundar Jul 16 '14 at 12:21
  • its thread safe. I find the following error in the Apache file: [Wed Jul 16 14:10:15.445328 2014] [ssl:warn] [pid 2772:tid 304] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name [Wed Jul 16 14:10:15.710526 2014] [ssl:warn] [pid 2772:tid 304] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name [Wed Jul 16 14:10:15.757326 2014] [mpm_winnt:notice] [pid 2772:tid 304] AH00354: Child: Starting 150 worker threads.` – kya Jul 16 '14 at 12:40
  • If there is no error associated with sqlsrv then you have to check your dll files is present or not. Please make sure you are modifying the correct php.ini file c:\xampp\php\php.ini. Check you extensions again after restarting the server http://php.net/manual/en/function.extension-loaded.php – Sundar Jul 16 '14 at 13:04
  • @user2995165 it appears that the port might be busy and hence the error. Check http://stackoverflow.com/questions/17440727/apache-shutdown-unexpectedly – Sarah Jul 17 '14 at 08:40
  • 1
    I am considering installing sqlexpress locally to test it. I will post any changes after installation. – kya Jul 17 '14 at 08:55
  • I think there is nothing todo with port. First you need to install the module in apache and it should display in the phpinfo() command. – Sundar Jul 17 '14 at 10:55
  • @Sundar, I just got it to work by installing SQL Express on the same machine. But now the issue is that I want to query a database on a different server – kya Jul 17 '14 at 11:01
  • You are loosing the track i think.. You have to check the phpinfo() is displaying the sqlsrv extension or not – Sundar Jul 18 '14 at 04:35
  • @Sundar it worked after installing SQLExpress locally – kya Jul 18 '14 at 05:57
0

What worked for me on windows 10 64bit and php 5.6. is the 3.2 version of the driver downloaded from here:Microsoft SQL Server driver for PHP

Stefan Michev
  • 4,795
  • 3
  • 35
  • 30