Forum Moderators: coopster

Message Too Old, No Replies

Connecting to DB with MSSQL & PHP

Call to undefined function: mssql_connect()

         

andylarks

4:00 pm on May 19, 2004 (gmt 0)

10+ Year Member



I saw a posting on the 1st May exactly the same as this, but wasn't sure whether you are supposed to start a new subject. If not, sorry, won't do it again.

I should start by saying that I have this working on one server, but I'm trying to migrate the php pages to a new server. I have uncommented the php.ini line for the mssql extension. I've restarted the services, and run up phpinfo, which doesn't say anything about mssql?

I've tried copying the php_mssql.dll to winnt/system32 just in case, no joy :(

jatar_k replied with some info about ntwdblib.dll. I tried copying that from the server on which it's working to the WINNT/system32 directory on which it isn't working, but that's not changed anything, (although I haven't rebooted, would that be the difference?)

Anyone got any other thoughts on what I should try?

Thanks

Birdman

4:45 pm on May 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It sounds like Jatar_k may be right. I would definately try rebooting.

From: [php.net...]

Applies to : IIS 5.0, PHP 4.3.4, MS-SQL 2000

If you try to connect to a host with multiple SQL-Server instances, you have to copy the ntwdblib.dll from a MS SQL 2000 installation to the system32 directory of your webserver.

The ntwdblib.dll bundled with php 4.3.4 does not support multpiple server instance.

I used the DLL version 2000.80.194.0 that came with MS SQL Server 8.00.194.

Example:
$dbhost="server_name\instance_name,port_number";
$dbuser="foo";
$dbpass="foo";
$dbname="foo";
$db=mssql_connect($dbhost,$dbuser,$dbpass);
mssql_select_db($dbname,$db);

andylarks

8:30 am on May 20, 2004 (gmt 0)

10+ Year Member



Thanks Birdman.

Ok, so I tried rebooting, still have the same problem. I then looked a bit harder at the post from the php.net site, and noticed that they put:

$dbhost="server_name\instance_name,port_number";

I've simply been putting the server_name. Now, at the risk of looking like a complete idiot, what is the instance_name and how do I find it out, that and the port number. That said, it still doesn't explain the fact that mssql_connect is an unknown function... does it?

andylarks

2:26 pm on May 20, 2004 (gmt 0)

10+ Year Member



OK, duh!

Somewhere along the line, I re-commented the php_mssql.dll extension. I've un-commented it again, and now I have a new error, which I think relates to my last post:

Warning: mssql_connect(): Unable to connect to server: my.ip.address - Could not connect to database:

Timotheos

3:34 pm on May 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it's any consolation my setup just has the server name. No mention of instances (?) which seem to have something to do with running multiple instances of SQL server. I'd suspect something in the user authorization. I had a dickens of a time getting mine to connect. Good luck.

andylarks

8:01 am on May 21, 2004 (gmt 0)

10+ Year Member



So now I have this:

-----------------------------------------
$host = "my.server.ip.address";
$user = "foo";
$pass = "foo";
$dsn1 = "my_database";
$admit = mssql_connect($host,$user,$pass) or die("Could not connect to database: ".mssql_get_last_message());
-----------------------------------------

It now tells me that it cannot connect to server.

Timotheos, you said you had a hard time making this work, so what did you do to get it to connect? Or anyone else who's got this working :)

Thanks all

Birdman

10:51 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried "localhost"?

$host = "localhost";

Timotheos

4:03 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi andylarks,

Sorry it was one of those situations where you get something working and you're not sure why since you've been trying so many different things. I'm sure we've all had moments like those.

I like the localhost suggestion though.

Tim

andylarks

9:08 am on May 25, 2004 (gmt 0)

10+ Year Member



Hi guys

again, thanks for all your posts, I appreciate all the help.

Birdman - not exactly sure why you're suggesting that I try host as localhost when the MSSQL database is on a remote host?

Thanks

Timotheos

3:10 pm on May 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Still working at it eh? I didn't understand that it was remote either.

You know I really expect the line die("Could not connect to database: ".mssql_get_last_message());
to give you more of an error message when it can't connect. Like something about an unauthorized user. Do you get anything else?