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: https://www-01.ibm.com/marketing/iwm/iwm/web/pickUrxNew.do?

Link: https://pan.baidu.com/S/1G9TFSWEGBWR3QMFXDJUGR
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

d456210e9e07cf644923289ee0b8f332

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
    else:
        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;" \
             "CLIENT_LOCALE=zh_cn.utf8;DB_LOCALE=zh_cn.GB18030-2000"\
                 % (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
IfxPy.free_result(stmt)
IfxPy.free_stmt(stmt)
IfxPy.close(connect)

 #, Чтобы окно не выплескивалось
os.system("pause")

Reference article:

Link 1: https://www.cnblogs.com/yu121/p/14290846.html
Link 2: https://github.com/OpenInformix/IfxPy/wiki

Leave a Comment