Python Connection Informix database

Currently focused ODBC or IFXPY method requires environment variables, relying on system Informix driver and EXE wrapped without drivers

(Bag Band’s Bag MySQL driver can run directly)

Relatively speaking, ifxpy is better, just set up the Informix Client SDK

Download SDK, install ifxpy to see blog link 1 below (Linux)

It also provides Windows64 -bit. If you need Linux to go to the official website to download, you need to register an account

Official website download address:

Code extraction: XYLN
After copying this section, launch the Baidu Web Disk Mobile Phone APP, which is more convenient to operate

If it is Windows, you only need to set up the following environment variablesLD_LIBRARY_PATH


Special attention, the number of digits must be matched, for example,

Special attention, GBASE8S or 8T, etc., the following two parameters need to be modified according to the actual database format to adjust

CLIENT_LOCALE = zh_cn.utf8; DB_LOCALE = zh_cn. GB18030-2000

The code appears as follows:

import os
import sys
import IfxPy

#  Путь доступа
import pyodbc

def resource_path(relative_path):
         iftattr (sys, 'frozen', false): #IS -пакет ресурс
        base_path = sys._MEIPASS
        base_path = os.path.abspath(".")
    return os.path.join(base_path, relative_path)

 Server = "Пример имени"
 Database = "Имя библиотеки"
 Host = "IP -адрес"
 Порт = конечный номер
 Uid = "имя пользователя"
 Pwd = "пароль"
connectStr = "PROTOCOL=onsoctcp;SERVICE=%s;UID=%s;PWD=%s;DATABASE=%s;HOST=%s;SERVER=%s;" \
                 % (PORT,UID, PWD, DATABASE, HOST,SERVER )

connect=IfxPy.connect(connectStr, "", "")

 # Данные запроса
sql = "SELECT * FROM bblx"
data = ()
stmt = IfxPy.exec_immediate(connect, sql)
dictionary = IfxPy.fetch_assoc(stmt)

rc = 0
while dictionary != False:
    rc += 1
    print (dictionary)
    dictionary = IfxPy.fetch_assoc(stmt)

 # Close Connection
# Free up memory used by result and then stmt too

 #, Чтобы окно не выплескивалось

Reference article:

Link 1:
Link 2:

Leave a Comment