# Miscellaneous > Database Programming >  Connection from php to mssql

## newphpcoder

Good day!
I have a problem in my connection in mssql to php. I tried my best to fix my problem. Here is some data I could give for better understanding.

I used:

SQL Server 2005 Express
SQL Server Management Studio Express
IIS 6.0
php 5.2.4

I do all the configuration that I know to work my connection from php to mssql like this:

1. I put the php location in the system variable PATH.
2. I download the ntwdblib.dll version that work in sql server 2005.
3. I put the ntwdblib.dll in the system32, and php folder.
3. I configure my php.ini
I uncommented the ff:
extension=php_mssql.dll
extension_dir=".\ext"
doc_root ="C:\Inetpub\wwwroot"
cgi.force_redirect = 0
mssql.secure_connection = On

And this is my information in my SQL Server:

Server Type: Database Engine
Server name: ISM\SQLEXPRESS
Authentication: Windows Authentication
Username: MR\Administrator ----This username was hiding
Password:    ----Password was hiding


I change also my php code:



```

<?php
//mssql.secure_connection = On
//Need to uplaod ntwdblid.dll from net

$myServer="ISM\SQLEXPRESS";
//$connectionOptions=array("Database"=>"AdventureWorks");
//$myUser = "MRM\Administrator";
//$myPass = "xoxoxo";
$myDB = "dbtest";

//Connect to the database
$dbhandle = mssql_connect($myServer) or die("Could not connect to SQL Server");

//Select a database
$selected = mssql_select_db($myDB) or die("Could not open database");

echo "You are connected to the dbtest";
?>


```

As you can see I commented the $myUser and $myPass, because I had read a forum that if the authentication is Windows Authentication, no need to used username and password to connect.

After all this configuration still I can't connect to mssql
Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\testconn.php on line 12

It's almost 2 weeks I tried to solved this problem.I don't know what is missing or what is the possible solution in my problem..

I dont know what the problem is and what the configurations I need to do are.

I hope somebody can suggest or help me to fix my problem, because I really need to fix it.

Thank you in advance

----------


## rmiao

You have to tell sql server it's windows authentication, look at samples in http://www.connectionstrings.com/sql-server-2005.

----------


## newphpcoder

> You have to tell sql server it's windows authentication, look at samples in http://www.connectionstrings.com/sql-server-2005.


I do all the configuration that i know to work my connection from php to mssql like this:

1.I put the php location in the system variable PATH.
2.I download the ntwdblib.dll version that work in sql server 2005.
3.I put the ntwdblib.dll in the system32, and php folder.
3.I configure my php.ini
I uncommented the ff:
extension=php_mssql.dll
extension_dir=".\ext"
doc_root ="C:\Inetpub\wwwroot"
cgi.force_redirect = 0
mssql.secure_connection = On

I change also my php code:


<?php
//mssql.secure_connection = On
//Need to uplaod ntwdblid.dll from net

$myServer="ISM\SQLEXPRESS";
//$connectionOptions=array("Database"=>"AdventureWor  ks");
//$myUser = "MRM\Administrator";
//$myPass = "xoxoxo";
$myDB = "dbtest";

//Connect to the database
$dbhandle = mssql_connect($myServer) or die("Could not connect to SQL Server");

//Select  a database
$selected = mssql_select_db($myDB) or die("Could not open database");

echo "You are connected to the dbtest";
?>


After all this configuration still I can't connect to mssql
Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\testconn.php on line 12

----------


## rmiao

Is MRM\Administrator a windows account? Tried connect with sql authentication?

----------


## newphpcoder

> Is MRM\Administrator a windows account? Tried connect with sql authentication?


My connection using Windows Auhtnetication is working now. My problem now is the connection to database, I try this code:


```

$db = "dbtest"; 
$selected = mssql_select_db($db) or die('MSSQL error' . mssql_get_last_message()); 



```

and the output is:
MSSQL error.The server principal "[domain name]\IUSR_[Computer name]" is not able to access the databse "database name" under the current security context. 

Honestly, I don't have any idea about this error.

----------


## rmiao

Please don't double posting.

----------

