Chapter 20. EDB Connector/ODBC

Table of Contents
20.1. Setting up the ODBC Driver
20.1.1. Windows
20.1.2. Linux
20.2. Usage Samples
20.3. PHP
20.4. Python

The ODBC driver for EnterpriseDB is edb-odbc. ODBC is a standard database access method developed with the goal of allowing access to any data from any application.

This manual is not intended as a complete guide to ODBC programming, but should help to get you started.

20.1. Setting up the ODBC Driver

This section describes the steps you need to take before you can write or run programs that use the ODBC interface.

The install of EnterpriseDB provides for the deployment of the edb-odbc driver. Choose the ODBC Driver under the Client Connectors branch in the InstallShield Wizard.

20.1.1. Windows

Within the Windows environment, a new ODBC Data Source Definition (DSN) is configured by using the "Data Sources (ODBC)" menu option found under "Administrative Tools". This brings up the ODBC Data Source Administrator.

By clicking the "Add" button on the ODBC Data Source Administrator, the "Create New Data Source" wizard is started. Here the edb-odbc driver, which was deployed as part of the installation process, will appear. By selecting the "EnterpriseDB 2005" driver from the list and clicking on "Finish", the specific edb-odbc configuration screen will be launched.

On the edb-odbc setup screen, the database specific information is configured. The following fields are required to create the DSN:

  • Database - the name of the EnterpriseDB database desired

  • Server - the location of the EnterpriseDB server

  • Port - the port that the EnterpriseDB instance is running (5444 is the default)

The following fields are optional when creating the DSN:

  • Description - some text explaining the DSN in more detail

  • User Name - the user name to connect to the EnterpriseDB database. This can be provided at runtime.

  • Password - the password to connect to the EnterpriseDB database. This can be provided at runtime.

20.1.2. Linux

When the edb-odbc driver is deployed on a Linux platform, an ODBC Driver Manager is laid down to enable to use of the driver from other application on the Linux platform. The packaged Driver Manager with EnterpriseDB is unixODBC version 2.2.11, which can be found at http://www.unixodbc.org. To compact the deployment size and to reduce the number of external dependencies, unixODBC has been built without GUI support. This results in the need for some simple configurations from the command line.

To add a reference for unixODBC Driver Manager to find the edb-odbc driver, the following entry needs to be made in the file:

/opt/edb-2005/8.0.x.x/odbc/odbcinst.ini

[EnterpriseDB]

Description=EnterpriseDB ODBC driver for Linux and Windows
Driver=/opt/edb-2005/8.0.x.x/odbc/lib/edb-odbc.so
Debug=0
CommLog=1

For an application on the Linux platform to access the edb-odbc driver, a DSN needs to be created. This DSN creates a reference between the edb-odbc driver and the specific EnterpriseDB database desired. To add this reference, the following entry needs to be made in the file:

/opt/edb-2005/8.0.x.x/odbc/odbc.ini

   
[EnterpriseDB]

Description         = EnterpriseDB 

Driver              = EnterpriseDB 

Trace               = yes

TraceFile           = /tmp/odbc.log

Database            = edb

Servername          = localhost

UserName            = edb

Password            = edb

Port                = 5444
 

Within the DSN definition in odbc.ini, the following fields are required to create the DSN:

  • Driver - the odbc driver defined in odbcinst.ini

  • Database - the name of the EnterpriseDB database desired

  • Servername - the location of the EnterpriseDB server

  • Port - the port that the EnterpriseDB instance is running (5444 is the default)

Values for the following fields are optional when creating the DSN:

  • Description - some text explaining the DSN in more detail

  • Trace - the value of this field will not affect the connectivity. If the value is set to "Yes", a trace file is created.

  • TraceFile - the directory location of the trace file.

  • User Name - the user name to connect to the EnterpriseDB database. This can be provided at runtime.

  • Password - the password to connect to the EnterpriseDB database. This can be provided at runtime.

Once the steps are completed, the configuration can be tested using the unixODBC utility, isql. From the Linux command line, isql is run with the following syntax: