zoukankan      html  css  js  c++  java
  • python 操作MySQL避坑1064

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

      

  • 相关阅读:
    php上传excle文件,csv文件解析为二维数组
    transition的使用
    数组
    快捷键
    SCSS历史介绍与配置
    18-async函数
    this的指向问题
    媒体查询
    13-Set和Map数据结构
    15-Iterator和for…of循环
  • 原文地址:https://www.cnblogs.com/hoganhome/p/12210578.html
Copyright © 2011-2022 走看看