首頁  >  問答  >  主體

用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中文网2741 天前360

全部回覆(3)我來回復

  • 伊谢尔伦

    伊谢尔伦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,))
    

    這個是最找到的答案。我得到了正確結果。
    提醒一下,我是用的python3.4

    回覆
    0
  • 黄舟

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

    你是怎麼取得結果的,cursor.fetchone()

    回覆
    0
  • 大家讲道理

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

    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,))

    回覆
    0
  • 取消回覆