Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MySQL: AttributeError: cursor

81 views
Skip to first unread message

Kevin Murphy

unread,
Feb 11, 2012, 12:40:09 PM2/11/12
to
Hi All,
I'm using Python 2.7 and having a problem creating the cursor below.
Any suggestions would be appreciated!

import sys
import _mysql

print "cursor test"

db =
_mysql.connect(host="localhost",user="root",passwd="mypw",db="python-
test")

cursor = db.cursor()

>>>
cursor test

Traceback (most recent call last):
File "C:\Python27\dbconnect.py", line 8, in <module>
cursor = db.cursor()
AttributeError: cursor

Albert W. Hopkins

unread,
Feb 11, 2012, 1:07:25 PM2/11/12
to pytho...@python.org
You are using the low-level C API wrapper (not sure why). Most people,
I believe, would use the pythonic API:

>>> import MySQLdb
>>> db = MySQLdb.connect(host='localhost', user='root', passwd='mypw',
db='python-test')
>>> cursor = db.cursor()

The low-level API is... well.. for when you want to do low-level stuff.
You probably want the pythonic API.

-a


0 new messages