search

Home  >  Q&A  >  body text

用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

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

PHP中文网PHP中文网2827 days ago402

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:42:46

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

    This is the best answer I found. I got the correct result.
    Reminder, I am using python3.4

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:42:46

    How did you get the results,cursor.fetchone()

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:42:46

    The parameters of execute are wrong. The second parameter must be a sequence or dict. It can be changed to the following.

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

    reply
    0
  • Cancelreply