PHP to SQL Server connection

Discussion in 'Databases' started by Rafliv, Jan 6, 2014.

  1. Hi,
    I can connect with SSMS, and I can link to a SQL Server table with MS Access, but I can not connect with this PHP -

    <?php
    $uid="DB_xxxxx_crm_user";
    $pwd="trxxxxxe9";
    $serverName="s07.Winhost.com";
    $connectionInfo = array( "UID"=>$uid,"PWD"=>$pwd,"Database"=>"DB_67707_crm");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
    echo "Unable to connect.</br>";
    die( print_r( sqlsrv_errors(), true));
    }
    ?>

    This is the error message -
    Unable to connect.
    Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1
    Code:
     => -1 [2] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. [message] => [Microsoft][SQL Server Native Client 10.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. ) [1] => Array ( [0] => HYT00 [SQLSTATE] => HYT00 [1] => 0 [code] => 0 [2] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired [message] => [Microsoft][SQL Server Native Client 10.0]Login timeout expired ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => -1 [code] => -1 [2] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. [message] => [Microsoft][SQL Server Native Client 10.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. ) )
    
    I am absolutely and tremendously grateful for any help!!
     
    Last edited by a moderator: Oct 14, 2015
  2. Hey Rafliv, I created a test script for you, when you change the "XXX" variables to the correct credentials you will be able to see it can query your MS SQL database from PHP code, feel free to change the SQL statement in the example script to suit your own needs.

    Since we have a restriction on the types of files that can be uploaded, download this text document, open it up in notepad and enter your database credentials, save, and change the file extension to PHP before you upload it to your hosting space to test.
     

    Attached Files:

    Michael, ComputerMan and Elshadriel like this.
  3. Huh... it was connecting all along but I only tested for a failed connection! Thanks for opening my blood-shot eyes, Patrick. The next step was to bring back some live data and your code was just the ticket. You rock, man!
     
    Michael, ComputerMan and patrickcasey like this.
  4. Patrick - I want to say thank you for your reply to Rafliv. Your snippet just saved me. I spent all day this past Friday trying to figure out why this would not connect to our server. Monday morning now and just found your post. It works finally. Thank you.

    Now I am off to integrate this into the tool I created over a week ago.

    -Jeff
     
    ComputerMan and Michael like this.

Share This Page