1

我已经安装了 Python 2.7 和 mysql-python 2.7。我想执行此代码以在 Python 中测试 MySQL:

import MySQLdb
db = MySQLdb.connnect(host = "localhost",
                      user="Bishnu Bhattarai",
                      passwd = "password",
                      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]

但它显示了错误:

Traceback (most recent call last):
  File "C:\Users\Bishnu\Desktop\database", line 2, in <module>
    db = MySQLdb.connnect(host = "localhost",
AttributeError: 'module' object has no attribute 'connnect'

问题是什么?

4

1 回答 1

5

connect尝试从:)中删除第三个“n”

于 2013-01-23T09:12:24.533 回答