Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php SQL Server connection 1

Status
Not open for further replies.

Kurt111780

Technical User
Nov 20, 2003
235
GB
Hello, I am new to php and SQL Server. I am having trouble getting php connected to SQL Server.

What i did:
Installed PHP 4.2 using installer for IIS
Installed SQL Server Express on same server
copied the php_mssql.dll to php folder
copied ntwdblib.dll to System32 folder
uncommented php_mssql.dll in the php.ini file

Warning: mssql_connect(): Unable to connect to server: localhost in D:\ on line 18
Unable to connect to server

Code:
$db = mssql_connect("localhost","username","password") or die("Unable to connect to server");
mssql_select_db("myDatabase");
$result = mssql_query("SELECT * FROM myTable");

What could I be doing wrong?

Thanks,
Kurt

It's only easy when you know how.
 
even on localhost, sometimes I have had problems with the port settings or the firewall installed on the machine. is everything opened up portwise?

"Together we can make 'computer illiterate' a dirty word."
 
SQL server is a service. I assume the service is running. Is it running under the appropriate user? The service should require a system account or account with system rights. Try checking on that...

"Together we can make 'computer illiterate' a dirty word."
 
i have just taken a look at the php.net site on this topic. there is a page full of really useful looking notes form users who have been unable to connect to their shiny new sqlexpress databases and similar. broadly the news seems to be:

you can do it.
but why bother - use pdo odbc instead
if you really want to do it you will need a newer dll than that supplied by php
servername is not just the servername but also the instance name. ie "servername/instancename"
you have to have tcp/ip and named pipes enabled.

check out for the full gamut.

you might also have a look at for a function to return error messages from sql server. this may aid your debugging.

I'm with the posters on the first link though: use odbc unless there is a good reason not to.
 
It was the ntwdblib.dll file. I found one on server running sql server 2000 and copied it to the php folder. The one that came with php didn't work.


Thanks,
Kurt


It's only easy when you know how.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top