Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.