tsql works, php doesn't, accessing MSSQL DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zootal1
Forum Newbie
Posts: 2
Joined: Mon Sep 01, 2014 3:55 pm

tsql works, php doesn't, accessing MSSQL DB

Post by zootal1 »

freetds.conf:
[localz2]
host = 10.0.0.2
port = 1433
tds version = 8.0

Pretty straight forward, and works fine with tsql. With tsql I can connect and query the database.

PHP code:
$mssql_connection = mssql_connect('localz2','sa', 'password');

This insists:

Warning: mssql_connect(): Unable to connect to server:

I'm pulling my hair out, what is left of it, over this one. Why, oh why, would tsql work but mssql_connect in PHP not?

Note this has nothing to do with a web server, I'm running the php code in a console.

Slackware 14.1 32 bit
PHP 5.5.16
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: tsql works, php doesn't, accessing MSSQL DB

Post by requinix »

Try a different tds version - 7.2 or 7.0, for instance.
zootal1
Forum Newbie
Posts: 2
Joined: Mon Sep 01, 2014 3:55 pm

Re: tsql works, php doesn't, accessing MSSQL DB

Post by zootal1 »

I had to change it to 8.0 just to get it to work with tsql. With it set to 7.0, it wouldn't even work with tsql.

But oddly enough I found this in my PHP ./configure parms:

'--with-mssql=/usr/local/freetds'

Which is wrong, it has to be:

'--with-mssql=/usr/local'

And that was all it took to get PHP working. When I configure freetds I was pretty sure I used:

./configure --prefix=/usr/local

because if you put freetds in /use/local/freetds it won't work with PHP even if you configure PHP with '--with-mssql=/usr/local/freetds' and I haven't had the time to figure out why.....weird...I must have been using and old ./configure line when I upgraded PHP.....
Post Reply