Re: HOWTO: FreeTDS for Newbies (almost complete)
From: Jochen Daum (jochen.daum_at_cans.co.nz)
Date: Tue, 25 Nov 2003 14:15:32 +1300
On 24 Nov 2003 17:08:24 -0800, firstname.lastname@example.org (Google Mike)
>The latest is that I can get an mssql.so compiled and loaded properly
>(I think), but then the code won't work and it won't display the real
>reason for the error. It displays no error at all but crashes the
>script, not processing the rest of it, and then displays no error
>about the crash.
>RH9 comes with 4.2.2. That's like mega old. Here it is 2003 and 4.2.2
>came out in like 2001. No wonder Red Hat decided that they'd need to
>make the Fedora project!! For the luv of...@#%$#...geesh!
>Anyway, 4.2.2 tarball won't compile on my system using the method
>above, and it's ./configure --with-mssql=shared, not
>--with-mssql,shared. It's =, not comma. My documentation mistake.
>Anyway, it still wouldn't compile properly.
>Went with 4.3.4 tarball -- was the latest stable build. Surely they
>would have the mssql.so file ironed out by now. This compiled
>properly, created a .so file, and I copied it to /usr/lib/php4 (where
>RH9 puts the .so files).
>RH9 is a little funny. The php.ini file tells you that you need to
>make a file called mssql.ini in /etc/php.d directory. The
>/etc/php.d/mysql.ini file should look like:
I would expect to put that in php.ini
>That's it and I found that this works in loading the so properly. Of
>course, other ways to load this extension are to add the line you see
>above inside php.ini, or to use dl('mssql.so') to the top of your php
>Remember -- after editing php.ini, restart Apache.
>Anyway, cool -- PHP provides 3 ways to load extensions dynamically.
>Okay, so I proved that I could load the .so file without error, but
>then I need the code to work. My code looks like:
> dl('mssql.so'); //can comment this out if you used one of the other 2
>php dynamic loading techniques
> $server = '188.8.131.52,1433'; //you'll need to change
> $user = 'sa'; //may need to change
> $pass = 'passwordgoeshere'; //you'll need to change
> echo "before connect...<BR>\n";
> $conn = mssql_connect($server, $user, $pass);
> echo "before select_db...<BR>\n";
> $db = mssql_select_db('pubs', $conn);
> echo "before query...<BR>\n";
> $rows = mssql_query('select * from authors', $conn);
> echo "before fetch_array...<BR>\n";
> $row = mssql_fetch_array($rows);
> echo "before dumping data for a row...<BR>\n";
> echo $row . ' ' . $row . ' ' . $row;
>Well, that wouldn't work -- it stops after "before connect" without
>error. So I tried changing the comma "," in $server to a colon ":".
It always only worked for me with 184.108.40.206:1433
>So, I figured I needed to change $server to "myservername", and then
>add this to /etc/freetds.conf:
I'm not using this. Neither did I need any ENV setting for FreeTDS.
>host = 220.127.116.11
>port = 1433
>tds version = 7.0
>This had the same exact result as the previous $server variable
>So then I tried mssql_pconnect instead of mssql_connect. Same result.
>So I tried a SQL 7 server instead of 2K. Same result -- just shows the
>first echo statement and never gets past that and never shows an
Hmm. You tried the telnet again, I suppose.
>So, here's my latest thoughts:
>* The 4.3.4 mssql.so file that I generated is either a work in
>progress by the PHP team, or I have a version conflict with a 4.2.2
>PHP and a 4.3.4 mssql.so. I might have to go down the long road of
>learning how to compile Apache with all the proper modules enabled
>like they are now on my system, and compile PHP 4.3.4 in the same way.
>Not looking forward to it.
You don't need to compile apache to compile php. I actually have never
compiled apache. I ran it as an rpm on Suse and from a deb on debian
>* I may have to either shell out and do a tsql call from a PHP page,
>which seems to work and would require parsing -- and is also not a
>recommended option unless you're desperate; or, I'll need to build my
>own socket server with VB6 and the Winsock control in a control array
>on a Windows system, using ADO to process the incoming SQL calls from
>a PHP socket call.
It really must work somehow. Maybe look into tcpdump to see whats
happening under the bonnet.
>* Or I'll need a .so that someone has made for PHP that enables SQL
>Server connections in another way.
I would try to compile PHP from a tarball (4.3.4) and turn on mssql.
>* Or I'll use PHP to call JDBC to access MS SQL, since that works
>because Microsoft has made a JDBC driver for MS SQL 2K. I don't like
>that solution because it requires giving into Java, which I am trying
>to abandon because PHP was so much cooler.
>* So, if you're looking to do MS SQL Server connections from within
>RH9, you're in for some severe fun....NOT.
Whats exactly the reason again, why you couldn't compile PHP?
Here's my configure line for 4.3.2:
./configure --with-mysql --with-apxs
--with-crack=/var/www/install/cracklib2.7 --with-mssql --with-gd
--with-png-dir --enable-gd-native-ttf --with-ttf --with-curl
--enable-wddx --with-zlib-dir= --with-informix=/opt/informix
--enable-sockets --with-freetype-dir --with-ldap
You can remove pretty much everything, so you have
./configure --with-mysql --with-apxs --with-mssql
What is the exact problem you get with a tarball and this?
-- Jochen Daum - CANS Ltd. PHP DB Edit Toolkit -- PHP scripts for building database editing interfaces. http://sourceforge.net/projects/phpdbedittk/