Chris Fazzio
Chris Fazzio

Reputation: 375

Connect to SQL Server 2008 from Webhost PHP file?

Can anyone point me in the right direction for connecting to a SQL Server 2008 database from my website via php?

I would assume its not much different then connecting to a MySQL server.. Any help please, Thanks

Upvotes: 2

Views: 1375

Answers (3)

jkoech
jkoech

Reputation: 367

I would warn you, it's not a fantastic thing connecting SQL Server 2008 with PHP. I did succeed once, though it was on my local machine running windows. Have a look at the microsoft tutorial on how to connect SQL Server 2008 with PHP here http://msdn.microsoft.com/en-us/library/cc793139%28v=sql.90%29.aspx and the link below will guide you as well. Good luck. http://hafizbadrie.wordpress.com/2010/02/16/how-to-connect-php-with-sql-server-2008/

Upvotes: 0

Nickolas Tuttle
Nickolas Tuttle

Reputation: 208

I believe this is the script you need...

More on it at http://php.net/manual/en/function.sqlsrv-connect.php

$serverName = "serverName\sqlexpress"; //serverName\instanceName
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
     echo "Connection established.<br />";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}

Upvotes: 1

Petah
Petah

Reputation: 46050

Look into the MS SQL Server PDO interface:

Upvotes: 0

Related Questions