Connection String for PHP-MSSQL

<?
/*
PHP MSSQL Example

Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/

$data_source=’mssql.dnsracks.com,1533′;
$user=’database_user_name’;
$password=’database_password’;

// Connect to the data source and get a handle for that connection.
$conn=mssql_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < ’4.0′){
exit(“Connection Failed: . $php_errormsg” );
}
else{
exit(“Connection Failed:” . errormsg() );
}
}

?>

***********************************************************************************************************

ODBC

<?
/*
PHP MSSQL Example

Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/

$data_source=’dns_name’;
$user=’database_user_name’;
$password=’database_password’;

// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < ’4.0′){
exit(“Connection Failed: . $php_errormsg” );
}
else{
exit(“Connection Failed:” . odbc_errormsg() );
}
}

// Disconnect the database from the database handle.
odbc_close($conn);
?>

For MSSQL 2005
data_source = 74.86.116.10,1433

For MSSQL 2008
data_source = 72.18.135.197,1433

This post has No comment. Add your own.

Comments are closed.