简体   繁体   English

Python / MySQLdb / cursor.executemany()

[英]Python/MySQLdb/cursor.executemany()

I am performing a very simple query to a given MySQL database. 我正在对给定的MySQL数据库执行非常简单的查询。 Let's say: 比方说:

>>> cur = mydb.cursor()
>>> results = cur.executemany("select field from table where field = %s", ('value1', 'value2', 'value3'))
>>> print results
4

So far so good... 到现在为止还挺好...

>>> rows = cur.fetchall()
>>> print rows
field for value3

So the problem is that it prints answer only for value3 and not for value2 and value1 因此,问题在于它只为value3打印答案,而不为value2value1打印答案

How can I fetch the entire result for the operation I am doing. 如何获取正在执行的操作的整个结果。

Thank you! 谢谢!

Instead: 代替:

print rows 

Try this: 尝试这个:

for r in rows:
    print r

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM