Fatal error: Call to undefined function sqlsrv_connect ()

2

I think many of you have seen the following error:

  

Fatal error: Call to undefined function sqlsrv_connect ()

I have done everything, change versions read many forums and then nothing. I have the following extensions enabled in php.ini

extension=php_pdo_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_ts.dll

In the error.log nothing related, only the error itself:

  

[Wed Mar 15 18: 18: 35.602697 2017] [: error] [pid 8080: tid 1728] [client   :: 1: 49291] PHP Fatal error: Call to undefined function   sqlserv_connect () in ...

As you can see the phpinfo.php does not look bad. Have if someone can give me a hand. I would appreciate immensely.

    
asked by Juan Fontecha 16.03.2017 в 00:48
source

2 answers

0

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 to the end of the extensions section:

    • extension = php_sqlsrv_56_ts.dll
    • 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 the PHP.INI and restart the apache service

  •   

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

        
    answered by 16.03.2017 / 09:59
    source
    -1

    It is not necessarily because of the issue that the drivers are signed or not, what usually happens is that we do not download the correct driver.

    For this Witchcraft to work it is necessary that you review the version of PHP that you have, in your case 5.6, therefore you must download from the official microsoft site the correct library. In the case of PHP 5.6 you must download the microsoft dirver that has the ending 32, for the PHP 7 version you must use the library with termination 40

    Then follow the instructions in this manual link

    and to make the connection, what I was fined to is the following example:

    // we declare the function that makes the connection to the BDD

    function OpenConnection()  
    {  
        try  
        {  
            $serverName = "nombre de la instancia"; 
            $connectionOptions = array("Database"=>"nombre de la BDD",  
                "Uid"=>"usuario del SQL", "PWD"=>"El PAsword"); 
            $conn = sqlsrv_connect($serverName, $connectionOptions);  
            return $conn;
            /*
              //en mi caso no reconoce la función FormatErrors() por eso lo 
                comenté
            if($conn == false)  
                die(FormatErrors(sqlsrv_errors()));  
            */
        }  
        catch(Exception $e)  
        {  
            echo("Error!");  
        }  
    }  
    //Esta función genera ejecuta una consulta cualquiera
        function ReadData($tsql)  
    {  
        try  
        {  
            $conn = OpenConnection();  
            $tsql ;  
            $getNames = sqlsrv_query($conn, $tsql);  
            /*if ($getNames == FALSE)  
                die(FormatErrors(sqlsrv_errors()));  */
            $productCount = 0;  
            while($row = sqlsrv_fetch_array($getNames, SQLSRV_FETCH_ASSOC))  
            {  
                echo($row['nombre']);  
                echo("<br/>");  
                $productCount++;  
            }  
            sqlsrv_free_stmt($getNames);  
            sqlsrv_close($conn); 
    
        }  
        catch(Exception $e)  
        {  
            echo("Error!");  
        }  
    } 
    

    // here we send the function calling by placing the query as parameter

    ReadData("SELECT algo FROM algunaTabla")  ;
    

    I hope someone will help me I took days to understand the new way to connect to PHP SQL SERVER

        
    answered by 24.04.2017 в 15:58