Page 1 of 1

[SOLVED] PHP and MSSQL Connection

Posted: Thu Aug 04, 2005 12:41 pm
by quadoc
I've the following code below. It's running on Windows 2000 Web Server. Every time I run it, it gave me the error below. My DNS server name is "ga04", my windows password is "test", database name is "Student". Do I need to use "localhost" for the hostname? Could someone tells me why? :?

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: ga04 in c:\Inetpub\wwwroot\schoolProject\TestConnect2.php on line 23 Unable to open database


$hostname = "ga04";
$username = "test";
$dbName = "Student";
$password = "Student";

mssql_connect($hostname,$username,$password) or DIE("Unable to open database");

mssql_select_db($dbName) or DIE("Unable to open table");
$query = "SELECT * from users";
$result = MSSQL_QUERY($query);
$nrow = MSSQL_NUM_ROWS($result);code.

Posted: Thu Aug 04, 2005 12:48 pm
by feyd
if the SQL server is on the web server, it's best to use localhost, as that doesn't require network transmissions to talk to itself..

Posted: Thu Aug 04, 2005 12:54 pm
by quadoc
I got the same error after changing the hostname to "localhost".

Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in c:\Inetpub\wwwroot\schoolProject\TestConnect2.php on line 23 Unable to open database.

Do I use other variables correctly? What else do I need to check for? :?

Posted: Thu Aug 04, 2005 12:56 pm
by feyd
check that the database name you are using is absolutely correct (including case)..

Posted: Fri Aug 05, 2005 10:59 am
by quadoc
Thanks for the tips. I had the server name incorrect. :)