PHP connect to MSSQL

Posted on 2013-11-29
Last Modified: 2014-03-12

I've got a web application running on CentOS, WHM/cPanel. PHP version 5.4
And a Windows 2000 server with a MSSQL database.

How can i connect remotely to this database?

I've already tried several options:

$cs = mssql_connect ( 'IP:1433', 'User', 'Password' ) or die ( 'Can not connect to server' );
mssql_select_db ( 'DatabaseName', $cs ) or die ( 'Can not select database' );

Open in new window


Warning: mssql_connect(): Unable to connect to server: IP:1433 in /home/property/public_html/test.php on line 1
Can not connect to server

Thanks in advance!
Question by:DATA99
  • 2
  • 2
  • 2
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39685417
That does look like an odd hostname. The format for the host name is:


servername, port number
myServer, 1433

IP address, Port Number
123.456.789.123, 1433

Author Comment

ID: 39685498
It is an IP address, I just replaced it with IP…  The servers are not in the same network, 1 is a virtual cloud server.
LVL 43

Expert Comment

by:Chris Stanyon
ID: 39685509
OK. Did you read the rest of my comment - because it's a Windows server the port number comes after a comma, not a semi-colon.
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

LVL 83

Expert Comment

by:Dave Baldwin
ID: 39685972
Actually, 'mssql' on a Linux server also requires FreeTDS to create a 'DSN' that must be used in the 'mssql' connect statement.  'php_mssql' on Linux is an old and poorly maintained extension and does not support some newer datatypes.  Since you are on CentOS which is a RedHat clone, you can probably use Microsoft's SQL driver and get much better access.  Here's info and links:

Author Comment

ID: 39689580
Hi DaveBaldwin,

I've setup freetds etc:

But still no luck..
LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 39690433
Here's article from EE about doing it.  It is not 'intuitive'.

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question