0

I'm using xampp and I'm trying to connect my PHP project to SQL Server to make reports. But there's a conflict with sqlsrv_connect() function.

My version of PHP installed in XAMPP is 5.6.23 and my connection file contains this:

<?php
$serverName = "MyserverName\MyinstanceName"; //serverName\instanceName

$connectionInfo = array("Database"=>"Database_Example");
$conn = sqlsrv_connect($serverName, $connectionInfo);

if( $conn ) {
     echo "Conexión establecida.<br />";
}else{
     echo "La conexión no se pudo establecer.<br />";
     die( print_r( sqlsrv_errors(), true));
}
?>

Also, I have downloaded the next files and I have extracted in "C:\xampp\php". PHP dll's

And I have added to "php.ini" file this code:

extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll

I´ve tried too with the exact version of the driver for my PHP and it doesn´t work.

Drivers Version

And this is the error that appears when I'm trying to connect:

Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\Inventory\conexion.proc.php

1 Answer 1

2

I have solved my own problem! I write the answer for someone with the same problem.

The version of the driver have to be the same of your PHP, not superior. You have to extract the dll files in "C:\xampp\php\ext" not in "C:\xampp\php".

After that another problem will appear: ODBC Driver 11

You have to dowload ODBC Driver 11 on this link: https://www.microsoft.com/en-us/download/confirmation.aspx?id=36434

And then when the driver will be installed, your code with queries will work!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.