Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

I was 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 did install it and included the below code in to my php.ini file which is 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 wamp server has been running fine and so are the wampapache and wampsqld services. I am able to execute php.exe successfully. However, I was unable to make the connection to the SQL Server 2008 R2 where my database has been located. Please help!

EDIT 1: The wamp server has been running the wampmysql service while I am trying connection to SQL Server 2008 R2. Could this be the reason? Should I use the MySQL instead of the 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, which is the bin folder of the wamp server.

enter image description here

1 Answer

0 votes
by (12.7k points)

There are two php.ini files found, in my case, for wamp. One is under the php folder and the other one of it is in the C:wampbinapacheApachex.x.xbin folder. When we are connecting to the SQL through sqlsrv_connect function, we are referring to the php.ini file in the apache folder. Add the below (as per your version) to this file:

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

Want to be a SQL expert? Come and join this SQL Certification by Intellipaat.

Do check out the video below

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
...