zoukankan      html  css  js  c++  java
  • pymysql插入Null

    execute 可以自动将python的None转化为MySQL的NULL
    import pymysql
    a = ''
    b = 'NULL'
    c = None
    def updata():
        conn = pymysql.connect(host="localhost", port=3306, user="root", password="123", db="xctest")
        cursor = conn.cursor()
        sql="insert into kk(name,explains) VALUES (%s, %s)"
        # cursor.execute(sql, (a, "插入空字符串"))
        # cursor.execute(sql, (b, "手工转化NULL"))
        cursor.execute(sql, (c, "插入空置None"))
        conn.commit()
        print("haha")
    updata()
  • 相关阅读:
    JavaScript语言和jQuery技术1
    JSP2
    JavaScript语言和jQuery技术2
    MYSQL2
    JSP1
    JSP5
    JSP3
    Spring框架
    JSP4
    MYSQL3(查询)
  • 原文地址:https://www.cnblogs.com/yuanyongqiang/p/11183931.html
Copyright © 2011-2022 走看看