Reputation: 375
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
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
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