Pymysql插入不工作 [英] Pymysql Insert Into not working
本文介绍了Pymysql插入不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Eclipse中的PyDev运行...
import pymysql
conn = pymysql.connect (host ='localhost',port = 3306,user ='userid',passwd ='password',db ='fan')
cur = conn.cursor()
打印写入数据库
cur.execute(INSERT INTO cbs_transactions(leagueID)VALUES('test val'))
print写到db
结果是,在控制台的顶部,它表示C:... test.py,并在控制台中:
写入db
写到db
所以直到执行命令之后才会终止。但是当我在MySQL中查看表时,它是空的。没有插入记录。
首先,为什么不写入记录。其次,如何查看日志或错误,看看发生了什么。如果代码失败,通常会出现一些红色错误。
解决方案
你提交了吗? conn.commit()
I'm running this from PyDev in Eclipse...
import pymysql
conn = pymysql.connect(host='localhost', port=3306, user='userid', passwd='password', db='fan')
cur = conn.cursor()
print "writing to db"
cur.execute("INSERT INTO cbs_transactions(leagueID) VALUES ('test val')")
print "wrote to db"
The result is, at the top of the Console it says C:...test.py, and in the Console:
writing to db wrote to db
So it's not terminating until after the execute command. But when I look in the table in MySQL it's empty. A record did not get inserted.
First off, why isn't it writing the record. Second, how can I see a log or error to see what happened. Usually there should be some kind of error in red if the code fails.
解决方案
Did you commit it? conn.commit()
这篇关于Pymysql插入不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文