Forum Moderators: coopster

Message Too Old, No Replies

PHP and MSSQL?

Trouble getting both to work.

         

NooK

1:25 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



I am trying to connect to a mssql databse with ph but I just cannot seem to get it.

The company has just updated php with added mssql support and I can connect to the mssql databse using SQL Server Management Studio (So I dont think the problem lies on the databse side).

I am trying

<?php

$DBServer = ipaddress:port;
$DBUsername = dbusername;
$DBPass = dbpass;

$dbhandle = mssql_connect($DBServer, $DBUsername, $DBPass) or die ("Couldn't connect to SQL Server);
?>

And it keeps giving me the "Couldn't connect..." message and I dont know what to do.

I am afraid the guys did not get mssql installed properlly on their side as they said their knowledge on php was limited.

Anybody can help me up? Anybody has gotten this working?

Is there a way to get some sort of error message back from the SQL server to pinpoint the problem?

Best Regards

NooK

dreamcatcher

1:48 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Nook,

Try:

$dbhandle = mssql_connect($DBServer, $DBUsername, $DBPass) or die (mysql_error());

dc

WesleyC

4:18 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



Dreamcatcher--I'm afraid mysql_error doesn't work with mssql_connect. ;)

I've dealt with this issue an annoying number of times. Generally, the issue is with the newer versions of PHP--the ntwdblib.dll file distributed with PHP is apparently the wrong version, and must be replaced in order to successfully connect with Microsoft SQL. Do a Google search on ntwdblib.dll and you'll come up with something. :)

In addition, if you're attempting to connect to SQL Express 2005, you'll need to specify the instance name--generally "MachineName\SQLEXPRESS"--as the connection address.

[edited by: WesleyC at 4:20 pm (utc) on Aug. 17, 2007]

dreamcatcher

6:31 pm on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Dreamcatcher--I'm afraid mysql_error doesn't work with mssql_connect.

I never even saw that, thanks.

dc

WesleyC

6:37 pm on Aug 17, 2007 (gmt 0)

10+ Year Member



It's a mistake that's all too easy to make, I've done it myself several times. :P

NooK

12:52 pm on Aug 27, 2007 (gmt 0)

10+ Year Member



Thanks guys.

I unfortunatelly had to use ADODB to connect to the server but I am having a problem where if the query is unsuccessfull (Due for example to missing data such as trying to query a table that doesnt exist or create a databse without the permission to do so) it simply shows me no error at all and halts the webpage parsing.

Could you please take a look here

[webmasterworld.com...]

for a better explanation and hopefully someone has a some solution.

Best Regards

NooK

[edited by: NooK at 12:54 pm (utc) on Aug. 27, 2007]