用python的mysql.connector模块运行代码结果为空,但是在数据库命令行下运行有结果
PHP中文网
PHP中文网 2017-04-18 09:40:46
0
3
355

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中文网

认证高级PHP讲师

Antworte allen(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,))
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!