0

I have WAMP and am trying to connect to to my SQL Server 2008 database by entering a domain user and password using the following PHP command:

$serverName = "MySQLServer\Instance"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", 
                         "UID"=>"myADUserName", "PWD"=>"MyPassword");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

As I understand it, it is trying to authenticate with a SQL Server created user and not from the Active Directory, so I am getting the following error message:

Array ( [0] => 
   Array ( [0] => 28000 [SQLSTATE] => 28000 
           [1] => 18456 [code] => 18456 
           [2] => [Microsoft][SQL Server Native Client 10.0]
                  [SQL Server]Login failed for user 'myADUserName'. 
                  [message] => [Microsoft]
                      [SQL Server Native Client 10.0]
                      [SQL Server]Login failed for user 'myADUserName'.  
         ) 
        [1] => 
   Array ( [0] => 28000 [SQLSTATE] => 28000 
           [1] => 18456 [code] => 18456 
           [2] => [Microsoft][SQL Server Native Client 10.0]
                  [SQL Server]Login failed for user 'myADUserName'. 
                  [message] => [Microsoft]
                      [SQL Server Native Client 10.0]
                      [SQL Server]Login failed for user 'myADUserName'. 
         ) 
     )

Is this possible in PHP with WAMP?

I've read about changing the log on account in the wampapache service to myADUserName, but the user doesn't have access administrator access on the server to allow this and I wouldn't want to tie one account to all my PHP applications.

3
  • Did you solved your problem? Commented Jan 21, 2014 at 16:23
  • Not exactly what I wanted, but I ended up creating a Service Account in the Active Directory and assigning it to the wampapache service so it starts it. Commented Jan 21, 2014 at 20:11
  • But it's correct way to use windows authentication. Commented Jan 22, 2014 at 11:21

2 Answers 2

2

When you assign "UID"=>"myADUserName", "PWD"=>"MyPassword" you are using sql-authentication and not Windows authentication. But you can create that user/pwd combination into the sql-server as sql-login -> SQL Server Authentication.

When you are want to use windows authentication you don't need to specify uid and pwd. the authentication is taken from the running apache process. Of curse that one needs to be run into that windows account.

See Microsoft documentation

Remarks If values for the UID and PWD keys are not specified in the optional $connectionInfo parameter, the connection will be attempted using Windows Authentication. For more information about connecting to the server, see How to: Connect Using Windows Authentication and How to: Connect Using SQL Server Authentication.

Sign up to request clarification or add additional context in comments.

1 Comment

When you want to use windows authentication you don't need to specify uid and pwd. +1
0

It looks strange, but this one worked for me,

$dbName='dB-Name';
$dbUser='User1';
$dbPass='B4X345ZXsaoi0omkLH';

 $connectionInfo = array( "Database"=>$dbName, "UID"=>$dbUser, "PWD"=>$dbPass);

If you are using SQLSERVER this wont work with php 5.5(I'm using this version didn't test any other)

$connectionInfo = array( "Database"=>"DBName", "UID"=>"User1", "PWD"=>"B4X345ZXsaoi0kLH");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.