Kevin
Kevin

Reputation: 13226

Connect to remote MSSQL server with PHP

I need to connect to a remote database server with PHP to query and return data.

So far, I have tried this:

$connection = mssql_connect('[redacted]:1433\SQLEXPRESS', '[redacted]', '[redacted]');

and

$connection = mssql_connect('[redacted]', '[redacted]', '[redacted]');

Both result in FALSE, but no error thrown. What am I missing? It doesn't even seem to attempt to connect (fails very quick).

Upvotes: 0

Views: 2035

Answers (2)

Kevin
Kevin

Reputation: 13226

Good answer by AlexC, but what I wound up doing was converting the MSSQL database over to MySQL and performing the migration with the Migrate framework (Drupal).

Upvotes: 0

AlexC
AlexC

Reputation: 1141

Usually this isn't so much about the connection code as the setup of the external DB server. First try this: $connection = mssql_connect('[redacted]\SQLEXPRESS', '[redacted]', '[redacted]'); But you are connecting to SQL Express which by default doensn't accept any incoming TCP/IP requests, so if that doesn't work out, you'll need to check the configuration (or if it's truly external, have the DBA check it) and make sure:

  • it's set up to accept TCP/IP requests,
  • that the firewall is allowing that IP and port through, and
  • that the specific IP address your request is coming in on is accepting requests

Upvotes: 1

Related Questions