Entry
how to connect redhat linux php client to a remote interbase server
how to connect redhat linux php client to a remote interbase server
how to connect redhat linux php client to a remote interbase server
Sep 26th, 2002 10:48
Jeff Stern,
i struggled for days to get my php (on a linuux redhat 7.3 box) to see
our interbase server (on a remote win/nt machine), and found no docs
or help in all the right places.. so i offer this as a help to anyone
else who is struggling to get it configured. it probably won't be
perfect for you, but hopefully it will get you in the ballpark close
enough to save you a little time..
as far as i could tell (though it wasn't explicitly stated anywhere),
there are two options for connecting php to an interbase database:
1) directly
for this, you need to re-compile php, since redhat does not provide
the compile-flag that php needs
2) via ODBC
for this, you need to install the interbase client and easysoft
odbc drivers.
i chose 2), because support for ODBC *is* compiled into the PHP
distributed in the Redhat rpms.
for either one, however, you need to have a copy of the interbase
client library.
how to get it? the way i handled this was by downloading a demo trial
from Interbase (see below) but i believe there are other ways, as well.
also, it's not specified anywhere what rpms you will need, and this
adds more time/confusion to the mix. these are the RPM's i have
installed (by the time you read this, it may be dated info):
Prerequisite RPM's:
------------------
apache-1.3.23-14
unixODBC-2.2.0-5
php-4.1.2-7.3.4
php-odbc-4.1.2-7.3.4
i got all of these from the redhat cd (or a download mirror). the
IB65 demo will install at least 2 more rpm's..
now download the IB65 demo tar from borland. to do this, set your
browser to:
http://www.borland.com/products/downloads/download_interbase.html
click on "Trial download", log in (create account 1st if you need to),
and download 'IB65_eval_linux.gz'.
now run
tar -zxvf IB65_eval_linux.gz
and then cd to IB65_linux.
now, run ./setup, install interbase client only (choice 3), then the
easysoft/odbc rpms (choice 7). as the Install.txt says, add
/opt/interbase/bin to your path (in /etc/profile or ~/.profile or
.cshrc or wherever you want) and reboot or restart shell, etc.
make sure that your /etc/odbcinst.ini has a section for your drivers:
[INTERBASE]
Description = Easysoft Driver for Interbase
Driver = /usr/lib/libib6odbc.so
Setup = /usr/lib/libib6odbcS.so
FileUsage = 1
DontDLClose = 1
and that your /etc/odbc.ini has 1 section for each database you want
to connect to. the default from the installation looks like this:
[ib6]
Driver = INTERBASE
Description = interbase driver
Database = localhost:/opt/interbase/examples/employee.gdb
User = sysdba
Password = masterkey
With_Schema = 0
Dialect = 3
Charset =
Role =
Nowait = 0
but in my case, i changed the Database, User, and Password fields to
match the remote server that i need to connect to. (also, we are using
interbase 6.0.. i don't know how you'll do if you're using 5.x or
earlier). also, if you are using a Windows IB server, then unless you
have an alias set, your URL will have to include the drivename,
too. for instance:
Database = myserver.com:c:/path/to/database/file.gdb
..this can be a little stickler sometimes..
also, you don't need the unixODBC gui (ODBCConfig or gODBCConfig),
since all it really does is edit the 2 .ini files mentioned above.
also, if you want logs of your ODBC connections for debugging, etc.,
then you can add these lines to your /etc/odbcinst.ini file:
[ODBC]
Trace = Yes
Trace File = /tmp/sql.log
(though be careful, because it can grow large, fast).
now, when you run isql from the command-line, it would look like this:
% isql ib6
or
% isql -v ib6
if you want to see verbose output because you are having problems
connecting.
that's it!
now, you can just do normal odbc commands in your php, such as
$connection = odbc_connect("ib6", "", "") or die(odbc_error_msg());
or other variant.. remember to use the same DSN syntax (don't specify
the database URL directly). also, you don't need to supply interbase
user or password, since these are already included in the odbc.ini file
you set up.
also, you might want to change the permissions and ownership of
your /etc/odbc.ini file, since all your system users can currently read
the db username, password and DB-URL. so, something like this will work:
$ chomod 640 /etc/odbc.ini
$ chown root.apache /etc/odbc.ini
Problems:
========
1) if you get an error message (using the '-v' flag) like this:
[unixODBC][Driver Manager]Invalid string or buffer length
[ISQL]ERROR: Could not SQLConnect
then you might be trying to use the isql command incorrectly. that is,
you might be trying to use the database URL:
% isql server:/path/to/dbfile.gdb
if that is the case, DONT. it's not meant to do it that way. i know:
if you do an 'isql --help' and capture the stderr output, it will show
you to connect to a DSN but it doesn't explain what a DSN
is. apparently a DSN is the section-name in the odbc.ini file.
2) if you get an error message like this:
[unixODBC][Driver Manager]Can't open lib '/usr/lib/libib6odbc.so' :
libodbcinst.so: cannot open shared object file: No such file or
directory
[ISQL]ERROR: Could not SQLConnect
it might be because somehow your system got a symlink message up in
your libs directory. for instance, i had to go back and make one:
% cd /usr/lib
% ln -sf libodbcinst.so.1.0.0 libodbcinst.so
..your mileage may vary..
hope this was helpful