zoukankan      html  css  js  c++  java
  • python 连接informix

    参考地址:https://github.com/OpenInformix/IfxPy

    1. 下载安装  Informix Client SDK

        地址:链接:https://pan.baidu.com/s/1CXMkwUnhRl4StrhPJ4n5fw 

        提取码:

        解压,执行可执行文件即可

    2. 安装IfxPy模块

        pip install ifxpy

        pip若无法安装,可选择离线安装,下载安装包,执行:python setup.py install   即可

    3. 设置环境变量

       export LD_LIBRARY_PATH=${INFORMIXDIR}/lib:${INFORMIXDIR}/lib/esql:${INFORMIXDIR}/lib/cli

       以下是我的环境变量:

       export LD_LIBRARY_PATH=/opt/IBM/Informix_Client-SDK/lib:/opt/IBM/Informix_Client-SDK/lib/esql:/opt/IBM/Informix_Client-SDK/lib/cli

    4. 环境配置

        vim /etc/hosts:

                 ip 服务名    

         vim sqlhosts:

                   服务名    onsoctcp          服务名       服务名     g=g_服务名

        export INFORMIXSQLHOSTS=/data/sqlhosts

        vim /etc/services 

               服务名    27583/tcp

    导库报错:ImportError: libifgls.so: cannot open shared object file: No such file or directory

     原因:环境变量没有配对

    5. 连接informix数据库

    # Sample1.py
    import IfxPy
    
    def my_Sample():
        ConStr = "SERVER=服务器;DATABASE=库名;HOST=ip;SERVICE=端口;UID=用户名;PWD=密码;"
    
        try:
            # netstat -a | findstr  27583
            conn = IfxPy.connect( ConStr, "", "")
        except Exception as e:
            print ('ERROR: Connect failed')
            print ( e )
            quit()
    
    
    
        # Select records
        sql = "select tabname from systables where tabid>=100;"   #  查库下的非系统表
        # sql = "SELECT username FROM 'informix'.sysusers WHERE usertype IN ('D', 'R');"
        stmt = IfxPy.exec_immediate(conn, sql)
        dictionary = IfxPy.fetch_both(stmt)
    
        rc = 0
        while dictionary != False:
            rc += 1
            print (dictionary)
            dictionary = IfxPy.fetch_both(stmt)
    
        print( "Total Record Selected {}".format(rc) )
    
        # Free up memory used by result and then stmt too
        IfxPy.free_result(stmt)
        IfxPy.free_stmt (stmt)
    
        IfxPy.close(conn)
    
        print ("Done")
    
    ####### Run the sample function ######
    my_Sample()
  • 相关阅读:
    chrome远程调试真机上的app
    高性能Cordova App开发学习笔记
    eclipse导入cordova项目
    跨域后模拟器上还是不能显示数据
    跨域请求数据
    eclipse导入cordova创建的项目
    cordova添加platform
    sdk更新代理设置
    NPM安装之后CMD中不能使用
    android开发环境搭建
  • 原文地址:https://www.cnblogs.com/yu121/p/14290846.html
Copyright © 2011-2022 走看看