skip to Main Content

I need to connect to an Azure SQL DB from an external PHP app on shared cPanel hosting.

My host has enabled mssql_connect but wont enable MS’s recommended sqlsrv_connect in the shared environment.

I have whitelisted the webserver IP in Azure’s Portal, and whitelisted the DB address in cPanel.

The test script seems to try to connect, but cant. No error information is provided: http://app.hivve.com.au/api/

PHP is:

$db_server = "cjweb.database.windows.net:1433"; // update me
$db_username = "username";
$db_password = "password";

$conn = mssql_connect($db_server, $db_username, $db_password);

print_r(mssql_get_last_message());

Has anyone else been down this road? My host wont provide anymore assistance so Im stuck.

2

Answers


  1. Could you please try to connect as shown below? Please look at the user name.

    Add [aftermath] on the ~/.freetds.conf:

    [aftermath]
        database = mydatabase
        host = cjweb.database.windows.net
        port = 1433
        tds version = 8.0
    
    
    $myServer = "aftermath"
    $myUser = cjweb@cjweb
    $myPass = your_password
    
    $dbhandle = mssql_connect($myServer, $myUser, $myPass)
      or die("Couldn't connect to SQL Server on $myServer");
    
    Login or Signup to reply.
  2. What I found in Azure SQL document Quickstart: Use PHP to query an Azure SQL database that maybe you have lost the "UID" agrument.

    <?php
        $serverName = "your_server.database.windows.net"; // update me
        $connectionOptions = array(
            "Database" => "your_database", // update me
            "Uid" => "your_username", // update me
            "PWD" => "your_password" // update me
        );
        //Establishes the connection
        $conn = sqlsrv_connect($serverName, $connectionOptions);
    ?>
    

    You can first test Alberto Morillo’s code.

    Hope this helps.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search