Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP connect to MSSQL

Posted on 2013-11-29
6
Medium Priority
?
412 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39685417
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
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.
0
 
LVL 44

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.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 84

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

Author Comment

by:DATA99
ID: 39689580
Hi DaveBaldwin,

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

But still no luck..
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 1500 total points
ID: 39690433
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

719 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