美文网首页Python笔记
python笔记--(3)--[向MySQL数据库中插入null

python笔记--(3)--[向MySQL数据库中插入null

作者: FengBli | 来源:发表于2017-03-15 01:11 被阅读0次

    参考博客:菜鸟的成长的博客
    python中空值为None,而MySQL中的空值为NULL,在插入空值时可通过如下方法完成:

    import pymysql
    
    conn = pymysql.connect(host="localhost", user="root", passwd="12345", db="MyDB", charset="utf-8")
    
    cur = conn.cursor()
    
    cur.execute("**insert into** My_table(attr1, attr2, attr3) **values** (%s, %s, %s)",
                    (entry_1 **or** "NULL" , entry_2 **or** "NULL", entry_3 **or** "NULL"))
    
    cur.close()
    
    conn.commit()
    
    conn.close()
    
    

    相关文章

      网友评论

        本文标题:python笔记--(3)--[向MySQL数据库中插入null

        本文链接:https://www.haomeiwen.com/subject/qkiknttx.html