当前位置:   article > 正文

mysql cursor 1064_python 操作MySQL避坑1064

pymysql.cursors 执行sql 报错pymysql.err.programmingerror: (1064, "you have a

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near xxxxx)

pymysql操作数据库出现这种错误多半是语法问题,比如当我们使用如下语法是就会出现此错误

conn.execute("SELECT * FROM foo WHERE bar = %s AND baz = %s" % (param1, param2))

正确的写法如下

c.execute("SELECT * FROM foo WHERE bar = %s AND baz = %s", (param1, param2))

拓展:

python操作MySQL数据库

import pymysql

db = pymysql.connect(host=‘localhost‘, user=‘root‘, password=‘123456‘, port=3306, db=‘spiders‘,charset=‘utf8‘) cursor = db.cursor()

sql = ‘select * from students;‘

cursor.execute(sql)

cursor.close()

db.close()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/508942
推荐阅读
相关标签
  

闽ICP备14008679号