Connect PHP with SQLServer

0

Good morning I have a question, since I have a database in SQL SERVER 2014 and I am trying to establish a connection from PHP I already checked it and according to me my error is sending the IP address of the database server but I do not know if I'm missing anything. p>

<?php
$serverName = "1.1.1.1"; //serverName\instanceName
$connectionInfo = array( "Database"=>"Example", "UID"=>"sa", "PWD"=>"");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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

The error you send me is this:

  

Fatal error: Call to undefined function sqlsrv_connect ()

Thanks again for your help.

    
asked by Alberto Arenas 21.03.2017 в 16:16
source

2 answers

2

WHAT HAPPENS TO ME
I used the Microsoft drivers and it did not work.

HOW TO SOLVE IT
1. I downloaded the "Unofficial" drivers from
link
2. In the zip, there are the drivers for 32 and 64 bit PHP.

HOW TO INSTALL THEM (VERY IMPORTANT TO READ WELL)

  • Copy the DLL's to the PHP ext folder.
  • DLLs must be the same version with PHP installed
  • DLLs must match PHP if this is TS or NTS
  • In PHP.INI add the following lines at the end of the extensions section:
    A. extension = php_sqlsrv_56_ts.dll
    B. extension = php_pdo_sqlsrv_56_ts.dll
  •   

    EYE: The name of the DLL file must be of which it is being installed, in this example it is for PHP 5.6 TS

  • Save PHP.INI and restart apache service
  •   

    NOTE: I am using SQL Server 2016 SP1 and it works for me normal, Luck.

        
    answered by 21.03.2017 / 21:10
    source
    0

    You can use adoDB or Laravel (or some similar framework that allows you to configure the driver to connect to SQL Server ...) to connect PHP with SQL Server.

    link link

    Besides, I do not recommend using the user sa to connect with the sql instance ... better create a user to do this and assign it a dbowner.

    Greetings.

        
    answered by 21.03.2017 в 16:45