Azure PHP Application and Azure SQL Database


I have a PHP application on Azure and I want this application to connect to Azure SQL Database.

$servername = "";
$username = "user";
$password = "pass";
$dbname = "DB";

$conn= mssql_connect($servername,$username,$password, $dbname);

$sql = "INSERT INTO AOL (AgentId,FullName, Email)
VALUES ('1', 'Doe', '[email protected]')";

mssql_query($sql, $conn);

When I run this php script I get a 500 error.

Do you have experience with PHP on Azure and Azure SQL Database? Or must setting something on Azure for Azure SQL Database?




By default, Azure environment doesn't install php_mssql.dll extension, it installs php_sqlsrv.dll instead.

You can use sqlsrv() instead:

$serverName = "<servername>, 1433"; //serverName\instanceName
$connectionInfo = array("Database" => "<database_name>", "UID" => "<userid>", "PWD" => "<passowrd>");
$conn = sqlsrv_connect($serverName, $connectionInfo);

if ($conn) {
    echo "Connection established.<br />";

    $query = sprintf("SELECT 1 as test");
    $stmt = sqlsrv_query($conn, $query);
    if ($stmt === false) {
        die(print_r(sqlsrv_errors(), true));

    while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {


} else {
    echo "Connection could not be established.<br />";
    die(print_r(sqlsrv_errors(), true));

People are also looking for solutions to the problem: php - Adding +1 onto a MySQL value via button


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.