Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to code database connection using windows authentication method

Status
Not open for further replies.

hex6007

MIS
Sep 2, 2008
53
PH
Hello guys,

my problem is how to code connection to the database using my local MSSQL Server logging Windows Authentication method.

thanks in advance.

regards
 
This might be interesting for a variety of reasons!
I'm assuming your client web server is windows.
Looking at the standard documentation for mssql_connect it doesn't seem to have a parameter to use windows authentication. What happens if you just supply a server name in the connect parameters? Remember that the user name that will be used will by the username the web server process is running under.
If this doesn't work you might like to try the microsoft PHP driver (see ) which does support windows authentication directly.
Be interesting to see how you get on.
 
can you not use a dsn less connection through ADODB? and then apply windows authentication not to the connection but to the webserver?
 
You can but that means your going through the ODBC layer and therefore adding a bit of bagage.
I knocked this out
Code:
<?php

$server = mssql_connect(".");
mssql_select_db("alerts",$server);

$version = mssql_query('SELECT @@VERSION');
$row = mssql_fetch_array($version);
echo "current version is " . $row[0];

$user = mssql_query('SELECT user_name()');
$row = mssql_fetch_array($user);
echo "current user is " . $row[0];

$cnt = mssql_query('SELECT count(*) from alerts');
$row = mssql_fetch_array($cnt);
echo "cnt is " . $row[0];

?>
While tells me im 'dbo' (db owner) which I am, I havn't got any other user to test it with nor do I have IIS set up for php.
It does return information so I assume it's connected ok but I am on the same machine as the server so it might not be valid but should be (if you see what I mean?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top