Solved

PHP connect to MSSQL

Posted on 2013-11-29
6
382 Views
Last Modified: 2014-03-12
Hi,

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


Result:

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!
0
Comment
Question by:DATA99
  • 2
  • 2
  • 2
6 Comments
 
LVL 42

Expert Comment

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

serverName\instanceName
MYSERVER\SQLEXPRESS

or
servername, port number
myServer, 1433

or
IP address, Port Number
123.456.789.123, 1433
0
 

Author Comment

by:DATA99
Comment Utility
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.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
Comment Utility
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.
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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: http://msdn.microsoft.com/en-us/library/hh568451.aspx
0
 

Author Comment

by:DATA99
Comment Utility
Hi DaveBaldwin,

I've setup freetds etc:
http://linuxadministrator.pro/blog/?p=201

But still no luck..
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
Here's article from EE about doing it.  It is not 'intuitive'.  http://www.experts-exchange.com/Programming/Languages/C/Q_27424576.html
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
In this video tutorial I show you the main steps to install and configure  a VMware ESXi6.0 server. The video has my comments as text on the screen and you can pause anytime when needed. Hope this will be helpful. Verify that your hardware and BIO…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now