zoukankan      html  css  js  c++  java
  • python之pymysql

    import pymysql
    from pymysql.cursors import DictCursor
    # coon = pymysql.connect(host='211.149.218.16',port=3306,user='jxz',passwd='123456',db='jxz',charset='utf8')
    # cur = coon.cursor(DictCursor)#建立游标,仓库管理员,指定游标类型,返回字典
    # sql='select * from stu limit 2,9;'
    # # insert_sql = 'insert into stu VALUE (89,"nhy");'
    # # cur.execute(insert_sql)
    # cur.execute(sql)#执行sql语句
    # for c in cur:#直接循环游标,每次循环的时候就是每一列的数据
    # print(c)
    # # res = cur.fetchall()#获取sql语句执行的结果,一次性全部获取
    # # coon.commit()#提交
    # # print(res[0][1])
    # cur.close()
    # coon.close()
    def op_mysql(host,user,passwd,db,sql,charset='utf8',port=3306):
    import pymysql
    from pymysql.cursors import DictCursor
    coon = pymysql.connect(host=host,user=user,passwd=passwd,db=db,charset=charset,port=port)
    cur = coon.cursor(DictCursor)#指订返回数据的类型是字典
    cur.execute(sql)
    if sql.strip().startswith('select'):
    res = cur.fetchall()
    else:
    coon.commit()
    res = 'ok'
    cur.close()
    coon.close()
    print(res)
    return res
  • 相关阅读:
    javascript DOM事件总结
    MySQL索引优化实例说明
    CSV导出大量数据
    最详细的PHP flush()与ob
    XSS攻击(跨站攻击)
    MySQL视图
    MySQL索引
    待整理
    Height、clientHeight、scrollHeight、offsetHeight 、scrollTop、offsetTop
    Cookie和Session的区别
  • 原文地址:https://www.cnblogs.com/wmm007/p/7809988.html
Copyright © 2011-2022 走看看