我想通过python简单地访问mysql的数据库。但是当我运行这段代码时:
import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
port = "3306",
user="Bishnu",
passwd = "Pulchowk",
db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchall()
print row[0],"-->",row[1]
db.cose()
它给出了一个错误:
Traceback (most recent call last):
File "C:\Users\Bishnu\Desktop\database", line 6, in <module>
db = "student")
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
那是什么 TypeError :需要一个整数
为什么会出现这样的问题?要运行这段代码,我遇到了 3 个问题,但幸运的是这个论坛解决了我的两个问题,我想它也会解决吗?