But I don't want to learn .NET!
March 20, 2008 4:01 PM   Subscribe

How can I connect to a SQL Server 2005 database using windows authentication with PHP?

I'm working on a small PHP/MSSQL application at work, but I can only connect to the database server using windows authentication and I can't figure out how to make that happen. Is it even possible?
posted by logic vs love to Computers & Internet (6 answers total)
 
Nope, it's not. You need to set up a user that has SQL Server authentication.
posted by SpecialK at 4:14 PM on March 20, 2008


Of course it's possible.

Google:
SQL Server and PHP windows authentication

The more difficult thing is setting up the account that either IIS or Apache will login in as. I'm assuming your database server is distinct from your web server, which means your IIS or Apache process will have to login as a domain user that can be authenticated against.

But of course it's possible, there's a whole mssql library for PHP.
posted by patrickje at 4:36 PM on March 20, 2008


In particular, read: http://msdn2.microsoft.com/en-us/library/cc296205.aspx

Keep in mind that this is meant for IIS, and may not work nicely with Apache.
posted by devilsbrigade at 5:25 PM on March 20, 2008


I have done this.

What you want is the MS SQL Server Driver for PHP. Register one of the two DLLs, then add a reference to it in PHP.ini.
posted by mphuie at 5:32 PM on March 20, 2008


Patrickje, you're half right and half not right.

Using the default PHP driver for MSSQL, documented on php.net, you're actually using the FreeTDS drivers that were written before Microsoft got all snippety with their licensing and started suing people. The php_mssql extension is no longer compiled/shipped by default because of microsoft's lawyers, although I see now that Microsoft . FreeTDS cannot use Windows Authentication with MS-SQL. (Trust me, I used to struggle with this daily.)

Microsoft has released a PHP Driver for SQL Server 2005 as a community preview... in other words, it's not production-ready code. This PHP driver *can* use Windows Authentication.
posted by SpecialK at 5:33 PM on March 20, 2008


You can take an older ntwdblib.dll from a SQL 2000. if you're using IIS, you simply setup the site to run as a user with the necessary access to the database (you can do this with Apache as well, run the service as the user) and set mssql.secure_connection to "on" (1).

Run all my sites this way and it works fine.
posted by purephase at 6:43 PM on March 20, 2008


« Older How to form an equitable business partnership   |   A bucket of mangoes Newer »
This thread is closed to new comments.