• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 467
  • Last Modified:

PHP connect to MSSQL

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
DATA99
Asked:
DATA99
  • 2
  • 2
  • 2
1 Solution
 
Chris StanyonCommented:
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
 
DATA99Author Commented:
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
 
Chris StanyonCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Dave BaldwinFixer of ProblemsCommented:
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
 
DATA99Author Commented:
Hi DaveBaldwin,

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

But still no luck..
0
 
Dave BaldwinFixer of ProblemsCommented:
Here's article from EE about doing it.  It is not 'intuitive'.  http://www.experts-exchange.com/Programming/Languages/C/Q_27424576.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now