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!

connecting to MSSQL database

Status
Not open for further replies.

DaveC426913

Programmer
Jul 28, 2003
274
CA
How do I connect to an MSSQL database using PHP?

I'm using this:

$s = mssql_connect($myServer, $myUser, $myPass) or die("Couldn't connect to SQL Server on $myServer");

but the page just draws a blank on that line - no error.

Are there other configuration things I need to do?
 
Sorry, it actually reponds with:

Fatal error: Call to undefined function: mssql_connect()
 
Every search I do for installing this extension leads to info about installing PHP on an an OpenBSD system.

How do I install just that extension? If I give my IT guy the info, what file(s) should I tell him I need?

 
I believe your best solution is a recompile with the proper flags set... but I honestly don't know, I've never run BSD and my *nix servers were always debian so they're pretty darn easy to manage.
 
OK, got the extension installed, that gets me closer. Thanks!

Now, I'm getting a warning:
"Unable to connect to server: <IP>\FASTVIBEDB1 ... Couldn't connect to SQL Server on <IP>\FASTVIBEDB1"

This occurs on line: mssql_connect($myServer, $myUser, $myPass)


The most likely cause here is that the database server isn't configured properly. That "\FASTVIBEDB1" on the end of the DB server IP address is some legacy from days before our arrival. We don't quite understand its significance.

Now, it DOES work in VB/ASP. I've copied the server, un, pw anbd database name exactly from the VB/ASP code that accesses this same database.

I wish I could even tell you what that string means (other than that FASTVIBE is our company name), if this were a regular server, I'd call it a folder name.
 
The documentation says:
Requirements for Unix/Linux platforms.

To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. Source code and installation instructions are available at the FreeTDS home page: »
Have you done this ?,
if you have can you post some actual code and as much of the error as you can. I notice from the documentation that the mssql library doesn't have an errormessgae or errornum function which strikes me as odd.
However there is a function call mssql_get_last_message() you might like to look at.
 
Once you have FreeTDS set up, there is some configuring that needs to be done.

On Linux, I have to set up a connection definition in freetds.conf. It's similar to a ODBC definition, where for a given connection name you specify a host, port and TDS version number. This is documented in the FreeTDS user guide:



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top