用python的mysql.connector模块运行代码结果为空,但是在数据库命令行下运行有结果

新手上路,请多包涵

cursor.execute("SELECT article_num1,article_num2,citation_num1,citation_num2,shortest_path_length FROM colla WHERE colla.author_name1 = '%s'",name)

结果为None

但是在数据库的命令行里运行就有结果,这是什么原因?

阅读 3.3k
3 个回答
✓ 已被采纳新手上路,请多包涵
cursor.execute("SELECT article_num1,article_num2,citation_num1,citation_num2,shortest_path_length FROM colla WHERE colla.author_name1 = %s",(name,))

这个是最找到的答案。我得到了正确结果。
提醒一下,我是用的python3.4

你是怎样获取结果的,cursor.fetchone()

execute的参数错了,第二个参数必须是一个sequence或者是dict,可以改成下面这样。

cursor.execute("SELECT article_num1,article_num2,citation_num1,citation_num2,shortest_path_length FROM colla WHERE colla.author_name1 = '%s'",(name,))
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题