ODBC on linux HowTo

Posted on 2004-11-10
Last Modified: 2008-03-10
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 :)

Question by:gmailrules
    LVL 9

    Expert Comment

    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

    MyODBC (Connector/ODBC, Download from

    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/
    FileUsage       = 1

    My /etc/odbc.ini
    driver = /usr/lib/
    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.

    LVL 1

    Author Comment

    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 :-)
    LVL 9

    Accepted Solution

    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:

    To download unixODBC:

    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

    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.
    LVL 9

    Expert Comment


    To view the filelist of an installed RPM
    rpm -ql unixODBC
    LVL 1

    Author Comment

    Thank you!!!

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now