Jump to content

Connection error to SQL 2005 using php 5.3.7


scamquist

Recommended Posts

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

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'. ) )

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.