pymysql模块

匿名 (未验证) 提交于 2019-12-02 22:02:20
conn = pymysql.connect(host="127.0.0.1",#默认是本机                        port=3306, #默认3306                        user="root",#必填                        password='密码',#必填                        db="库名")#必填 #如果没有库会报pymysql.err.InternalError: (1049, "Unknown database '库名'") 所有我们编辑可以这样 try:     conn = pymysql.connect(host="127.0.0.1",#默认是本机                            port=3306, #默认3306                            user="root",#必填                            password='16745',#必填                            db="asds",)#必填 except pymysql.err.InternalError:     print('没有库')
cursor = conn.cursor(pymysql.cursors.DictCursor) #自定义游标类型为字典 cursor = conn.cursor()#默认是元祖

普通提交

count = cursor.execute('show tables') #返回值为受到影响的数据条数

防注入提交

table_name = input('table name :') count = cursor.execute('select table %s',(name,)) 
默认显示之前那一次显示的内容,只显示查看相关语法的内容,为返回值  cursor.fetchall() #查看全部 cursor.fetchone() #查看当前游标位置的一个值 cursor.fetchmay(N) #查看当前游标位置的n值
  • 相对位置

    cursor.scroll(1, "relative")

    cursor.scroll() #默认是相对位置

  • 绝对位置

    cursor.scroll(0, "absolute")

文章来源: pymysql模块
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!