hoganhome
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()

  

分类:

技术点:

相关文章:

  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-11-17
  • 2021-09-17
  • 2021-12-31
猜你喜欢
  • 2021-04-23
  • 2021-09-05
  • 2018-01-21
  • 2021-12-01
  • 2018-05-18
  • 2019-10-28
  • 2021-11-17
相关资源
相似解决方案