ODBC on linux HowTo

I need to know how to setup odbc to work on a linux machine that already has php4.3 installed.  I know there are built in commands in php to use mysql but i would like to use odbc.  I did some research and i guess i need iodbc or unixodbc installed and odbc connector for mysql.  I also read that alot of unix odbc is already built into php so it should be easier to install unlike if it were perl.  I need a for dummies howto because i know very little linux.  I only have access to the command line.  Any help would be much appreciated :)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi :-)

If you use RedHat, then you need 3 RPMS:
php-odbc (comes with RedHat CD's)

unixODBC (also comes with RH, but I'd recommend downloading the latest version from www.unixodbc.org)

MyODBC (Connector/ODBC, Download from http://dev.mysql.com).

Configuration options are pretty straitforward. They lie in /etc/odbc.ini and /etc/odbcinst.ini

My /etc/odbcinst.ini
# From the MyODBC package
Description     = ODBC for MySQL
Driver          = /usr/lib/libmyodbc3.so
FileUsage       = 1

My /etc/odbc.ini
driver = /usr/lib/libmyodbc3.so
description             = MySQL ODBC 2.50 Driver DSN
SERVER          = localhost
PORT            =
USER            = john
Password                = johnspassword
Database                = asampledb
OPTION          = 3
SOCKET          = /tmp/mysql.sock

As you can see, odbcinst.ini contains just the driver location whereas odbc.ini contains acual connection options.
Please make sure the the path to the driver is correct and there actually is a file there.

After installing, you can use the isql utility to check that your database connection is valid:
[root@server-express root]# isql asampledb
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
SQL> SELECT * FROM a_sample_table

From this point on, create a PHP page the uses the unixodbc (odbc_*) functions.

Please note, an invalid odbc_connect will cause php to segfault and you'll get a 'Page cannot be displayed' error on your browser. You have to debug this on your own without  the error message.
Note 2: Look in the mysql log for authentication errors. PHP might be restricted to use only a dedicated 'apache' user (could be also 'nobody'). You would have to create such a user and authorize it.

gmailrulesAuthor Commented:
im sure that that would help if i were not such a linux newbie.  i only have access to the server through putty so im not sure if the linux cds would help.  it would be nice if you could tell me the commands on how to download the files  unzip them and intsall them.  what folders would i install them in? And them maybe i could follow your instructions from there.  Thanks a lot for the help :-)
I gave a 'medium-sized' explanation because I couldn't really know what your level of expertese is, and because giving too elaborate replies may be both boring and a waste of e-tsik resources :-)

First, do download the RPM'S to the server, use the command 'wget'
To download the MyODBC RPM:
wget http://ftp.gwdg.de/pub/misc/mysql/Downloads/MyODBC3/MyODBC-3.51.09-1.i586.rpm

To download unixODBC:
wget http://umn.dl.sourceforge.net/sourceforge/unixodbc/unixODBC-2.2.10-1.i386.rpm

I could not supply a link for php-odbc because you haven't specified exactly what type of linux you are using. However, you can look for that RPM in http://rpmfind.net

Some useful RPM command (filenames are for example):
To upgrade/install an existing RPM:
rpm -Uvh unixODBC-2.2.10-1.i386.rpm

To see if an RPM is installed
rpm -q php-odbc

To view the filelist of an installed RPM
rpm -q unixODBC

Note, version numbers are not included when querying RPM.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

To view the filelist of an installed RPM
rpm -ql unixODBC
gmailrulesAuthor Commented:
Thank you!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.