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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Connect to MS SQL Server

Status
Not open for further replies.

skicamel

Programmer
Dec 24, 2001
126
US
I know someone has an easy answer to this and I'm embarassed to have to ask on such a basic task. I've been working with databases and reporting tools for some time, but want to start working on a front end. We've got offices in various cities, and I'd like to get some information to them without consistently having to either set up the Crystal reports into our billing system (12 databases) or exporting into Excel (folks out there doing this know what a pain in the backside this can be). I've only used PHP for a day and most of that day has been spent scanning the PHP Manual and this site for some help in connecting to a SQL Server database. I've tried the syntax in the manual and get parsing errors. I've tried the two scripts I could find on tek-tips to no avail (searching for mssql_connect). When I get past the parsing errors I get this error:

Fatal error: Call to undefined function: mssql_connect() in c:\phpdev\ on line 21

I can't figure this one out. I'm calling to a local database, but I've also tried it with one of the work databases with no luck. The best I could guess as to why this is happening is in the PHP manual....

The servername argument has to be a valid servername that is defined in the 'interfaces' file.

So my question(s) is(are): 1. If neither database I've tried connecting to are 'valid servernames that are defined in the "interfaces" file', then how do I make them such? 2. If this is not the reason for the error, any ideas why I'm getting this error, or any sample scripts I might try to get this to work?

I'm using PHP 4.0.6 and SQL Server 7.

Thanks in advance, folks, this site has been an absolute lifesaver.
 
Easy steps here...

1. If you get a message like "Fatal error: Call to undefined function: mssql_connect()", then this means you are not loading the module for MSSQL connectivity in php.ini. PHP does not by default run with all of additional modules enabled. On many of the database modules, you have to explicitly load them. In the case of MSSQL, you need the following:
a. put php_mssql.dll in your "C:\WINNT\SYSTEM32" folder (or whatever your system root is).
b. uncomment the line ';extension=php_mssql.dll' in php.ini (take away the semicolon)
c. enter the correct path to the extensions directory in php.ini, such as 'extension_dir = C:\WINNT\SYSTEM32\' (I found through trial and error that you have to have the trailing backslash in the directory path)
d. You must have either MSSQL itself installed on the server, or at least the MSSQL client admin kit, for remote connectivity.

2. Fortunately there are some defaults in PHP that are always available. For example, MySQL connectivity is always in by default, and so is ODBC. So, if absolute high performance is not critical, then you can simply connect to MSSQL through an ODBC System DSN. In this case, the syntax is exactly the same as if you are connecting to Access, or any other database that supports ODBC. Here is a tutorial on PHP and Access that can translate well into MSSQL/ODBC: -------------------------------------------

"Calculus is just the meaningless manipulation of higher symbols"
                          -unknown F student
 
Looks like that was the key issue...Thanks. But now the error message has only changed. I'm now getting:

Warning: MS SQL: Unable to connect to server: localserver in c:\phpdev\ on line 21

Any ideas there? Secondly, I tried the ODBC connect. It looks to have worked, but now it seems I need the connection ID to work with anything in the database. I can't find anything that tells me how to view this returned value... Any ideas?

Thanks again all.
 
Okay, I stumbled across the answer for the odbc connection id. I wasn't thinking in terms of variables. I should be good to go for what I'm playing around with, but I know the mssql_connect issue will eat at me until it's figured out. I'd still appreciate any input on that. Thanks, again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top