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.
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
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
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.
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.
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
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 !
Within MindTouch, go to "Control Panel" -> "Extensions" and click "Add Extension" and fill out the form as follow (click to enlarge) :
Details about the extension can be found from the ODBC Extension page. Once saved, you should see the extension running :

Within MindTouch, the following query :
{{ odbc.table("SELECT * FROM example") }}
should display a result like :
| File | Version | Size | Modified | |
|---|---|---|---|---|
| ||||
| ||||
| ||||
| Images 3 | ||
|---|---|---|
Add ODBC ExtensionODBC_Extension.jpg | ODBC Extension RunningODBC_Is_Running.jpg | ODBC ExampleResult_ODBC.jpg |
Copyright © 2011 MindTouch, Inc. Powered by