Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQLdb can't use cursorclass

I am trying to execute the following code:

import MySQLdb
import MySQLdb.cursors
conn=MySQLdb.connect(host = '127.0.0.1',
                     user = 'root',
                     passwd = 'root',
                     db = 'test',
                     cursorclass = MySQLdb.cursors.DictCursor)
cursor=conn.cursor()

But it gives me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 243, in cursor
  AttributeError: 'Connection' object has no attribute 'cursorclass'

Why is this?

like image 442
kongkong Avatar asked Dec 13 '22 12:12

kongkong


1 Answers

 import MySQLdb
 import MySQLdb.cursors
 conn=MySQLdb.connect(host = '127.0.0.1',
                         user = 'root', 
                         passwd = 'root',
                         db = 'test',)
cursor=conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)

This is a rough hack, but it may not be advisable to use it. The script with throw out dictionary object by default but the application might require an tuple or array.

like image 136
ramkrsna Avatar answered Jan 05 '23 08:01

ramkrsna