python MySQLdb不会插入

2024-06-08 03:12:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是python-mysql,下面是我用来插入数据库表的代码片段。由于某些原因,代码没有填充数据库中的任何行。没有引发异常,SELECT查询工作正常。在复制execute中的代码并在phpmyadmin中运行时,数据库会很好地填充。你知道吗

    import MySQLdb as mdb
try:
    con = mdb.connect(host='localhost', user='', passwd='', db='indoor')
    cur = con.cursor()
    cur.execute("INSERT INTO locationdata VALUES('1','1','1','1','1','1')")
    numrows = cur.execute("SELECT * FROM locationdata")
    print str(numrows) + " : total Rows"
    print cur.fetchone()
    if con.open:
      print "Hello DB"
except mdb.Error, e:
    Print "Error " + e. args [0]

你知道我遗漏了什么吗?你知道吗


Tags: 代码import数据库executemysql原因errorcon

热门问题