0
votes

I'm having a problem running my PHP project on our IIS with SQL Server 2019. My version of PHP is 7.0.26 and I have already imported SQLSRV DLLS.

When I try to login with my system, the following error is popping up:

Connection could not be established. Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'sa'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'sa'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'sa'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'sa'. ) )

This is some part of my connection string.

$myCon = array("Database"=>$myDB, "UID"=>$myUser, "PWD"=>$myPass);
$db = sqlsrv_connect( $myServer, $myCon);

Also, I tried to trace the error, like adding the wrong credentials to see if there is some changes on the error message but it is still the same.

We tried some configurations, like setting up the server authentication into "SQL Server and Windows Authentication Mode", firewall is disabled, and also setting up the Native client configuration.

IIS configuration was made setting MIME Type, default document, connection string, Application Pool, and all the path config was set.

I also installed only ODBC Driver 13, 2015 Redistributable, .NET 4 framework.

Can anyone help me? Thank you.

1
First create a new LOGIN (and needed USERs) for your web app, with the minimal amount of permissions needed and use that too. Then, if you fail to connect check the SQL Server's logs. The sa account should never be used by an application to connect. - Larnu
Is your issue solved? If your issue is solved then I request you to mark the helpful suggestion as an answer. This will help other people who face the same issue. If your issue still exists then try to refer the solution given by the community members. If then also you have any further questions then let us know about it. We will try to provide further suggestions to solve the issue. Thanks for your understanding - Jalpa Panchal

1 Answers

0
votes

The SA account is created during the installation process. The SA account is well known and often targeted by malicious users, so it is advisable to disable the sa account unless your application requires it. you could create a new account in the SQL server or use windows authentication for accessing the SQL database.

<?php
$serverName = "serverName\\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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

Refer below link for more detail on how to create a user and configure with iis:

https://forums.iis.net/post/2159167.aspx

https://docs.microsoft.com/en-us/sql/connect/php/programming-guide-for-php-sql-driver?view=sql-server-ver15

https://docs.microsoft.com/en-us/sql/connect/php/connecting-to-the-server?view=sql-server-ver15