scamquist Posted August 19, 2011 Share Posted August 19, 2011 I am trying to connect to my SQL 2005 DB using Windows Authentication with PHP 5.3.7. I am using IIS on Server 2003. I am getting this error: Connection could not be established. Array ( [0] => Array ( [0] => 28000 [sqlSTATE] => 28000 [1] => 18456 => 18456 [2] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. [message] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. ) [1] => Array ( [0] => 28000 [sqlSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. [message] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. ) ) Here is my code: <?php /* Specify the server and connection string attributes. */ $serverName = "(local)"; $connectionInfo = array( "Database"=>"Iris"); /* Connect using Windows Authentication. */ $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Unable to connect.</br>"; die( print_r( sqlsrv_errors(), true)); } /* Query SQL Server for the login of the user accessing the database. */ $tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())"; $stmt = sqlsrv_query( $conn, $tsql); if( $stmt === false ) { echo "Error in executing query.</br>"; die( print_r( sqlsrv_errors(), true)); } /* Retrieve and display the results of the query. */ $row = sqlsrv_fetch_array($stmt); echo "User login: ".$row[0]."</br>"; /* Free statement and connection resources. */ sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?> Any help will be appreciated Link to comment https://forums.phpfreaks.com/topic/245242-connection-error-to-sql-2005-using-php-537/ Share on other sites More sharing options...
scamquist Posted August 19, 2011 Author Share Posted August 19, 2011 The error message merged into the code. Sorry Connection could not be established. Array([0] => Array ([0] => 28000 [sqlSTATE] => 28000 [1] => 18456 => 18456 [2] => [Microsoft][sql Server Native Client 10.0] [sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. [message] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. ) [1] => Array ( [0] => 28000 [sqlSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. [message] => [Microsoft][sql Server Native Client 10.0][sql Server]Login failed for user 'GAMAY\IUSR_GAMAY-SRV1'. ) ) Link to comment https://forums.phpfreaks.com/topic/245242-connection-error-to-sql-2005-using-php-537/#findComment-1259597 Share on other sites More sharing options...
scamquist Posted August 21, 2011 Author Share Posted August 21, 2011 I found the solution using SQL Server Authenticatoin. Here is the code: <?php $serverName = "(local)"; $connectionInfo = array("UID" => "MyUserName", "PWD" => "MyPassword", "Database"=>"MyDatabase"); $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)); } ?> Replace MyUserName, MyPassword and MyDatabase with your actual values Link to comment https://forums.phpfreaks.com/topic/245242-connection-error-to-sql-2005-using-php-537/#findComment-1260088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.