[php] Fatal error: Call to undefined function sqlsrv_connect()

I have come across quite a few post regarding the same subject question, however I am still unable to resolve it and so I ask. I am trying to connect to sql in my php script. My connection string is:

/* Specify the server and connection string attributes. */
$serverName = "xxx-PC\SQLExpress";
$connectionOptions = array("Database"=>"Salesforce");
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false)
{
      die(print_r(sqlsrv_errors(), true));
}

I have installed and included the following in my php.ini file located under the wamp folder: C:\wamp\bin\php\php5.4.16:

extension=c:/wamp/bin/php/php5.4.16/ext/php_sqlsrv_53_ts.dll

My wampserver is running fine and so are the wampapache and wampsqld services. I am able to execute php.exe successfully. However I am unable to make the connection to SQL Server 2008 R2 where my database is located. Please help!

EDIT 1: The wamp server is running the wampmysql service while I am trying to connect to SQL Server 2008 R2. Could this be the reason? Should I be using MySQL instead of SQL? Any pointers?

EDIT 2: I do not see sqlsrv section at all when I run phpinfo() though I have added extension=php_sqlsrv_54_ts.dll in the php.ini file located in the bin folder of the wamp server.

enter image description here

This question is related to php sql-server wamp

The answer is


i have same this because in httpd.conf in apache PHPIniDir D:/wamp/bin/php/php5.5.12 that was incorrect


First check that the extension is properly loaded in phpinfo(); (something like sqlsrv should appear). If not, the extension isn't properly loaded. You also need to restart apache after installing an extension.


When you install third-party extensions you need to make sure that all the compilation parameters match:

  • PHP version
  • Architecture (32/64 bits)
  • Compiler (VC9, VC10, VC11...)
  • Thread safety

Common glitches includes:

  • Editing the wrong php.ini file (that's typical with bundles); the right path is shown in phpinfo().
  • Forgetting to restart Apache.
  • Not being able to see the startup errors; those should show up in Apache logs, but you can also use the command line to diagnose it, e.g.:

    php -d display_startup_errors=1 -d error_reporting=-1 -d display_errors -c "C:\Path\To\php.ini" -m
    

If everything's right you should see sqlsrv in the command output and/or phpinfo() (depending on what SAPI you're configuring):

[PHP Modules]
bcmath
calendar
Core
[...]
SPL
sqlsrv
standard
[...]

phpinfo()


If you are using Microsoft Drivers 3.1, 3.0, and 2.0. Please check your PHP version already install with IIS.

Use this script to check the php version:

<?php echo phpinfo(); ?>

OR

If you have installed PHP Manager in IIS using web platform Installer you can check the version from it.

Then:
If you are using new PHP version (5.6) please download Drivers from here

For PHP version Lower than 5.6 - please download Drivers from here

  • PHP Driver version 3.1 requires PHP 5.4.32, or PHP 5.5.16, or later.
  • PHP Driver version 3.0 requires PHP 5.3.0 or later. If possible, use PHP 5.3.6, or later.
  • PHP Driver version 2.0 driver works with PHP 5.2.4 or later, but not with PHP 5.4. If possible, use PHP 5.2.13, or later.

Then use the PHP Manager to add that downloaded drivers into php config file.You can do it as shown below (browse the files and press OK). Then Restart the IIS Server

enter image description here

If this method not work please change the php version and try to run your php script. enter image description here

Tip:Change the php version to lower and try to understand what happened.then you can download relevant drivers.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to wamp

WAMP won't turn green. And the VCRUNTIME140.dll error cURL error 60: SSL certificate: unable to get local issuer certificate How to enable local network users to access my WAMP sites? WampServer: php-win.exe The program can't start because MSVCR110.dll is missing Project Links do not work on Wamp Server ERROR: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it Apache won't start in wamp How to send email from localhost WAMP Server to send email Gmail Hotmail or so forth? Fatal error: Call to undefined function sqlsrv_connect() WampServer orange icon