Connecting to SQL Server via php

pushVTEC

Senior member
Aug 30, 2003
265
0
0
I've tried mssql_connect($server,$user,$pass) and it fails to connect everytime. I know all the input i'm sending to it is correct. What may be the problem with connecting? Host machine is running windows.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
this may sound silly, but .. are you sure you have started the server?
can you connect from command line or other client?

Also, have you checked these (from the PHP documentation):

Requirements for Win32 platforms.

The extension requires the MS SQL Client Tools to be installed on the system where PHP is installed. The Client Tools can be installed from the MS SQL Server CD or by copying ntwdblib.dll from \winnt\system32 on the server to \winnt\system32 on the PHP box. Copying ntwdblib.dll will only provide access. Configuration of the client will require installation of all the tools.

The MSSQL extension is enabled by adding extension=php_mssql.dll to php.ini.

Also, have you tried printing out the server message?
I've never used mssql, but i think this might be the way to get the error message (if any)

mssql_get_last_message -- Returns the last message from the server
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
mssql_get_last_message returns nothing... hmmm I can connect to the DB using EMS MS SQL Manager.
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
I can telnet to the server and it displays a black screen so I know it's accepting incoming connections. Why will it allow me to connect any way I want, except through php lol
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
I don't have access to them, I sent a message to tech support but thus far they have not been belpful at all. I tried echoing the last message from sql server but it just comes back blank.
 

juiio

Golden Member
Feb 28, 2000
1,433
4
81
mysql_connect("server", "user", "password") or die(mysql_error());

should give you some sort of error. If it doesn't, try

mysql_select_db("db") or die(mysql_error());

and see what happens.
 

pushVTEC

Senior member
Aug 30, 2003
265
0
0
Just went back to to writing the program. The provider hasn't gotten back to me. Here's the code I have:

<?php

$server="localhost";
$username="user";
$password="pass";
$sqlconnect=mssql_connect($server, $username, $password) or die(mssql_get_last_message()." SQL Server not responding.");

?>

The only message I get when it errors is the SQL Server not responding part. The username and password are the same ones that I use to log in VIA EMS MS SQL manager. Any other ideas?
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
Ensure there are no firewalls blocking TCP port 1433 or UDP port 1434. If you are using custom ports, ensure all firewalls are letting traffic on these prots through and/or forwarding them to the correct host. If localhost is your true server location, make sure you don't have a software firewall blocking these ports.

If your real error message is Server not responding, it is probably a SQL Server set up issue, as opposed to a PHP problem.