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

Issues with connection from IIS/PHP to seperate MSSQL2008 server

We are having a problem with PHP/MSSQL 2008/IIS.

Our webserver is as such.

Windows 2003
Running IIS 6 / PHP 5

Our Database server is as such
Windows 2003
Running MSSQL 2008

We are using SQL authentication. From the webserver I can connect using SQL2008's SQL Server Management studio from the webserver to the db server without issue. I cannot connect with PHP however. My php connection code is as follows
<?php
$con = mysql_connect("xxx.xxx.xxx.xxx","username","password");
if (!$con)
{die('Could not connect: ' . mysql_error());}
?>

This outputs the following message to the webpage when trying to view the page

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server during query in C:\Standards\inc\database\lukes_test.php on line 2

Fatal error: Maximum execution time of 90 seconds exceeded in C:\Standards\inc\database\test.php on line 2

Again.. I can connect fine outside of PHP but using the above connection code it will not connect.

Any ideas?
0
bbcac
Asked:
bbcac
  • 5
  • 5
1 Solution
 
lucius_theCommented:
Why are you using mysql_conect (), you are not using MySQL for a database :)
You're connecting to MS SQL, so:
http://php.net/manual/en/function.mssql-connect.php
0
 
bbcacAuthor Commented:
My mistake... I accidentally posted the wrong code.. I had stripped the code down to basics in order to troubleshoot and in the process replaced it with the wrong connection function. Here's the correct code:
<?php
$con = mssql_connect("server","user","pass");
if (!$con)
{die('Could not connect: ' . mssql_get_last_message());}
?>

and the repective error
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 10.1.167.102 in C:\Standards\inc\database\lukes_test.php on line 2
Could not connect:
0
 
lucius_theCommented:
Are you sure you CAN connect using just the IP address, username and password from the SQL server management studio on the other machine ? And not using something like compname\sqlexpress.

It happens often that the port 1433 is not setup as the default port on the server, ot the firewall service blocks it...
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
bbcacAuthor Commented:
I have 1433 setup as the TCP/IP port. Also, other systems can connect to that DB server fine. I can put name or IP in the address and it still doesn't work. The install is not an express install. This is a full blown MS SQL 2008 dedicated DB server.

0
 
lucius_theCommented:
Hm... I was thinking maybe the libraries you use in PHP don't support SQL 2008.

So, found this. It sais here:
http://www.easysoft.com/developer/languages/php/sql_server_unix_tutorial.html

that you should download the "SQL Server ODBC driver for PHP client platform", here:
http://www.easysoft.com/cgi-bin/productdownload.cgi?p=53

And there are some examples too. This is to connect through ODBC, not directly.

But I think the solution may be this (this is actually what are experiencing):
http://www.akamarketing.com/blog/99-php-sql-server-connection-problems-mssql_connect-functionmssql-connect-unable-to-connect-to-server.html

It sais you need the newer ntwdblib.dll for PHP since the old one doesn't connect to all versions of SQL Server. The link has all the details.
0
 
bbcacAuthor Commented:
Ok.. trying it now... standby
0
 
lucius_theCommented:
I have to leave the office now, will check your posts when I come home this evening...
0
 
bbcacAuthor Commented:
Looks great... this is exactly what the issue was.
0
 
bbcacAuthor Commented:
Upgrade the DLL and away you go!
0
 
lucius_theCommented:
Great, tnx for the points :)
Best regards and have a nice NY's eve !
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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