Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14611 reviews 1734 hosting providers

Questions & Answers

Connecting MsSQL database with PHP IIS7

Apr 29, 2012 by SaraSX
Hi there
Can anyone please explain to me how do I connect to MSSQL Database using PHP in IIS 7, I'm new to to PHP and I'm a bit confused here.
Any help would be really appreciated


2 Answers

0 votes
Apr 29, 2012 by TopNet
Using sqlsrv_connect, you can connect to a MSSQL databse using the following code:

$conn_array = array (
            "UID" => "username",
            "PWD" => "password",
            "Database" => "database_name",
            "Encrypt" => 1,
            "TrustServerCertificate" => 1) ;

$conn = sqlsrv_connect('database_server' , $conn_array);

if ($conn)
        echo 'MSSQL Connection successful';
        die( print_r( sqlsrv_errors(), true));

sqlsrv_close( $conn );

 If the connection is successful, it will return the message: "MSSQL Connection successful". If not, an error message will be displayed.
0 votes
Apr 30, 2012 by WebGuru
another method would be Using mssql_connect

this is the code that you can use


$uid = "username";
$db = "database_name";
$pwd = "password";
$host = "database_server";

$conn = mssql_connect($host, $uid, $pwd) or die('Could not connect')
    or die("Couldn't connect to SQL Server on $host");

$selected = mssql_select_db($db, $conn)
    or die("Couldn't open database $db");

echo "MSSQL Connection successful";