首页 > 数据库技术 > 详细

python 操作MySQL避坑1064

时间:2020-01-19 00:22:13      阅读:95      评论:0      收藏:0      [点我收藏+]
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()

  

python 操作MySQL避坑1064

原文:https://www.cnblogs.com/hoganhome/p/12210578.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!