[SOLVED] PHP and MSSQL Connection

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

[SOLVED] PHP and MSSQL Connection

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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? :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

check that the database name you are using is absolutely correct (including case)..
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post by quadoc »

Thanks for the tips. I had the server name incorrect. :)
Post Reply