• Python写的链接数据库存取数据


    Python写的链接数据库存取数据

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    from __future__ import print_function
    import os
    import sys
    import time
    import MySQLdb
    
    jscookid=sys.argv[1]
    # 打开数据库连接
    conn = MySQLdb.connect(host="mysql.feieryun.cn",port=3324,user="feieryun",passwd="feieryun",db="firadio_ssproxy",charset="utf8")
    
    # 使用cursor()方法获取操作游标
    #cursor = conn.cursor()
    #cursor2 = conn.cursor()
    
    # 使用execute方法执行SQL语句
    #cursor.execute("SELECT VERSION()")
    
    # 使用 fetchone() 方法获取一条数据
    #data = cursor.fetchone()
    
    def test():
      cursor = conn.cursor()
      cursor.callproc('proc_port_fetch',[1])
      rows = cursor.fetchall()
      cursor.close()
      cursor2 = conn.cursor()
      for row in rows:
        #print row
        os.system('python mujson_mgr.py -a -u '+bytes(row[1])+' -p '+bytes(row[1])+' -k '+row[2]+' -m aes-256-cfb -O origin -o plain -t '+bytes(row[3]))
        os.system('python mujson_mgr.py -e -u '+bytes(row[1])+' -p '+bytes(row[1])+' -k '+row[2]+' -m aes-256-cfb -O origin -o plain -t '+bytes(row[3]))
        cursor2.callproc('proc_port_fetched',[jscookid,row[0]])
      cursor.close()
      conn.commit()
    
    while True:
      test()
      print('.', end='')
      sys.stdout.flush()
      time.sleep(1)
    
    # 关闭数据库连接
    conn.close()
  • 相关阅读:
    js去前后空格
    IE7以上支持Fiddler 监听本地
    IE8 scriptX print 无法使用的bug
    那些相见恨晚的 JavaScript 技巧
    oracle sql
    JS人民币金额转大写程序
    div自适应高度
    .NET Remoting 使用最佳实践,(部分翻译)
    对DataTable 进行Distinct操作
    用财富的眼光看知识管理
  • 原文地址:https://www.cnblogs.com/xiangxisheng/p/7910327.html
Copyright © 2020-2023  润新知