Using PHP to connect to a remote MSSQL database
14:12 17 Apr 2015

My local environment is WAMP. For a few pages i have to access a remotely hosted MSSQL DB, run queries and get back results.

I have been supplied the following information(values masked):

  • IP address of the remote MSSQL machine: 11.22.33.44
  • Database Name: abcdefgh
  • Username: db_username
  • Password: db_password

I have never connected to a remotely hosted DB before. From the example at: http://php.net/manual/en/function.mssql-connect.php

I tried this in a test file, mssql-connect.php:

\ or 
// , when using a non default port number
$server = '11.22.33.44\abcdefgh';

// Connect to MSSQL
$link = mssql_connect($server, 'db_username', 'db_password');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
?>

I am somehow not able to connect. I tried all variations of the connection string:

$server = '11.22.33.44/abcdefgh';

$server = 'http://11.22.33.44\abcdefgh';

$server = 'https://11.22.33.44\abcdefgh';

$server = '11.22.33.44';

$server = '11.22.33.44:1431';

$server = '11.22.33.44,1431';

Every one of these(and variations of these) return 'Something went wrong while connecting to MSSQL'.

I have enabled mssql through php.ini and can see it phpinfo. Are there any additional strings that needs to be passed?

php sql-server remote-access