u013627033
懒儿
2017-03-05 19:35

用python操作mysql时无法在mysql里面添加数据

  • python
  • mysql
 def store(username,concern):#数据库存储
    cur.execute("insert into yinyangshi (username,concern) values (\"%s\",\"%s\")",(username,concern))
    cur.connection.commit
    #print(username,":",concern)

用print验证时能输出正确结果但是查看数据库并没有存到里面数据

 import pymysql
conn=pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='1236987455',db='mysql',charset="utf8")
cur=conn.cursor()
cur.execute("USE scraping")
cur.execute("insert into yinyangshi (username,concern) values (\"%s\",\"%s\")",("你猜","Null"))
cur.connection.commit()
cur.close()
conn.close()

下面的就能正确的添加进去数据

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答