Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot Call function sqlsrv_connect()

Tags:

php

sql-server

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));
}
like image 616
kya Avatar asked Dec 15 '22 21:12

kya


2 Answers

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
like image 160
Isaac Gachugu Avatar answered Dec 17 '22 09:12

Isaac Gachugu


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

like image 22
Sundar Avatar answered Dec 17 '22 09:12

Sundar