View Full Version : insert / access MSSQL users from PHP

12-26-2007, 06:08 AM

I am using MSSQL 2005 express edition and php 5.2.3.
I would like to create system MSSQL users through php (just like sa user for example) for Authentication purpose. How to do that?
Thanks in advance.

12-27-2007, 01:16 AM
Haven't used mssql in ages. Should be the same (similar) method to any other user creation, just gotta execute a query:

CREATE USER user_name
[ { { FOR | FROM }
LOGIN login_name
| CERTIFICATE cert_name
| ASYMMETRIC KEY asym_key_name
[ WITH DEFAULT_SCHEMA = schema_name ]

Check in the database forum or search the net for mssql specific syntax (knowing MS, its probably different than most others). I got this from the ms tech site, so it should be somewhat close anyways.
Oh, and this is a given, but you need to be a privileged user (Admin/root) to perform this, and generally, its unwise to connect to a database with administrative access to a database.