Johanna
Johanna

Reputation: 223

Mysqldb AttributeError: cursor

I am starting to use the mysqldb module in python and I seem to have some issues with the "standard" way of calling queries.

I understand that the standard way is to create a cursor and then use it to execute queries.

However, when I try to instanciate one, it gives me the following error :

AttributeError: cursor

My Database class looks like :

class Database():

    def __init__(self):
        server = "localhost"
        login = "login"
        password = "passws"
        database = "DB"
        my_conv = { FIELD_TYPE.LONG: int }

        self.conn = MySQLdb.connection(user=login, passwd=password, db=database, host=server, conv=my_conv)
        self.cursor = self.conn.cursor()

    def close(self):
        self.conn.close()

    def execute(self, query):
        self.cursor.execute(query)
        return self.cursor.fetchall()

For now I get it working by using the query method, but I feel not using the standard will give me trouble in the future.

Any idea ?

Upvotes: 2

Views: 10248

Answers (1)

Roman Bodnarchuk
Roman Bodnarchuk

Reputation: 29727

You are using wrong connection constructor.

MySQLdb.Connection instead of MySQLdb.connection should work.

Upvotes: 7

Related Questions