Was this page helpful?

Using the ODBC extension on Linux


    Open Database Connectivity (ODBC)
    allows a standardized access to a wide range of database systems. This page will describe how to use the native MindTouch ODBC extension on a Linux instance.

     

     

    Install unixODBC

    The first step is to install UnixODBC driver manager on your system :


    CentOS :

    $ yum install unixODBC php-odbc
    

    Ubuntu :

    $ sudo apt-get install unixodbc php5-odbc unixodbc-dev
    

     

    Install ODBC drivers for Linux

    Depending on the database you want to access, you'll need to download and install the corresponding linux ODBC driver from the provider.

    For this example, we will use the MySQL connector :

    CentOS :

    $ yum install mysql-connector-odbc
    

    Ubuntu :

    $ sudo apt-get install libmyodbc

     

    Configuring ODBC on Linux

    You can list the configuration files using the "odbcinst" command :

    $ odbcinst -j
    unixODBC 2.2.11
    DRIVERS............: /etc/odbcinst.ini
    SYSTEM DATA SOURCES: /etc/odbc.ini
    USER DATA SOURCES..: /home/user/.odbc.ini
    

    We will need to define our driver first, then we will add our DataSource.

     

    Configuring the driver

    The driver configuration is done within "/etc/odbcinst.ini". For adding the MySQL driver, add a section as follow :

    CentOS :

    [MySQL]
    Description  = ODBC for MySQL
    Driver       = /usr/lib/libmyodbc3.so
    Setup        = /usr/lib/libodbcmyS.so
    FileUsage    = 1
    

    Debian :

    [MySQL]
    Description  = ODBC for MySQL
    Driver  = /usr/lib/odbc/libmyodbc.so
    Setup  = /usr/lib/odbc/libodbcmyS.so
    FileUsage  = 1
    

    note: the Driver path could be different on your system, check what library has been installed by your ODBC driver.

     

    Configuring the DataSource

    The DataSource Name (DSN) can be defined in "/etc/odbc.ini". Let's add my MySQL database section :

    [test-connector]
    driver = MySQL
    Database = my_database
    Server = localhost
    Socket = /var/lib/mysql/mysql.sock
    

    Or with TCP connection

    [test-connector]
    Description = MySQL
    Driver      = MySQL
    SERVER      = localhost
    USER        = someuser
    PASSWORD    = somepassword
    PORT        = 3306
    DATABASE    = wikidb
    

    Testing the ODBC access

    Time to test our ODBC access on our database. This can be done from the command line as follow :

    $ isql -v test-connector db_username db_password
    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> select * from example;
    +-----------+-------------------------------+-----------+
    | id        | name                          | age       |
    +-----------+-------------------------------+-----------+
    | 1         | Timmy Mellowman               | 23        |
    | 2         | Sandy Smith                   | 21        |
    +-----------+-------------------------------+-----------+
    SQLRowCount returns 2
    2 rows fetched
    SQL>
    

    Everything looks good, now we should be able to use this DSN within MindTouch !

     

    Adding the ODBC extension to MindTouch

    Within MindTouch, go to "Control Panel" -> "Extensions" and click "Add Extension" and fill out the form as follow (click to enlarge) :

    ODBC_Extension.jpg

    Details about the extension can be found from the ODBC Extension page. Once saved, you should see the extension running :

    ODBC_Is_Running.jpg

     

    Testing the ODBC Extension

    Within MindTouch, the following query :

    {{ odbc.table("SELECT * FROM example")  }}
    

    should display a result like :

    Result_ODBC.jpg

     

    Related Links

    - EasySoft Documentation

    Was this page helpful?
    Tag page

    Files 3

    FileVersionSizeModified 
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by