Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > MySQL: AttributeError: cursor

Reply
Thread Tools

MySQL: AttributeError: cursor

 
 
Kevin Murphy
Guest
Posts: n/a
 
      02-11-2012
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
 
Reply With Quote
 
 
 
 
Albert W. Hopkins
Guest
Posts: n/a
 
      02-11-2012
On Sat, 2012-02-11 at 09:40 -0800, Kevin Murphy wrote:
> 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


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to tell if cursor is sqlite.Cursor or psycopg2.Cursor dmaziuk Python 3 01-25-2011 04:52 AM
Declare Cursor error while implementing SCROLL CURSOR invy C Programming 4 12-28-2006 02:35 PM
Changing DEFAULT cursor to WAIT cursor in ASP =?Utf-8?B?VG9tYXMgS2VwaWM=?= ASP .Net 1 04-05-2005 07:42 PM
Default Cursor Placement Bob Firefox 2 02-25-2005 05:17 AM
Cursor while typing FlyCat Firefox 2 08-01-2004 01:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57