[Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
Israel Evans
israel@lith.com
Fri, 22 Mar 2002 11:52:13 -0800
I think I've figured out the problem with the help of our good friends here
on the list.
I was using the CompatMysqldb module because that's the only real .py file
that looked right. I've since found out that after I install the MySQLdb
module I can just import MySQLdb and use the documentation on the Python
Database API Specification 2.0 found on the python.org site to figure out
how to use it.
Now I just have to figure out why localhost is not a recognized host when I
try to create a connection.
Thanks people.
~Israel~
-----Original Message-----
From: Danny Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: 22 March 2002 11:18 AM
To: Israel Evans
Cc: 'tutor@python.org'
Subject: Re: [Tutor] Mysqldb.py:::Cursor has no 'query' attribute?
On Fri, 22 Mar 2002, Israel Evans wrote:
> I've just started working with MySQL, and the Mysqldb module for python
and,
> as usual, I've run into some problems...
Do you mean the "Mysqldb" module, or the "MySQLdb" module? *grin* I've
used Andy Dustman's MySQLdb module with good success:
http://sourceforge.net/projects/mysql-python
> after I type the following code in the the Python shell...
>
> >>> import CompatMysqldb
> >>> conn = CompatMysqldb.mysqldb('test@localhost israel
> SuperSecretPassword1')
> >>> cursor = CompatMysqldb.Cursor(conn)
> >>> cursor.execute('select version(), current_date')
>
> ... I get the error:
>
> Traceback (most recent call last):
> File "<pyshell#4>", line 1, in ?
> cursor.execute('select version(), current_date')
> File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 243, in
> execute
> self.__conn.query(op)
> File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 123, in
> __getattr__
> return getattr(self.__curs, key)
> AttributeError: Cursor instance has no attribute 'query'
>
> Anybody know why and what I can do about it?
I'm not too familiar with CompatMysqldb.py. The equivalent code, using
MySQLdb, would look like:
###
import MySQLdb
conn = MySQLdb.connect(db='test@localhost',
user='israel',
passwd='SuperSecretPassword1')
cursor = conn.cursor()
cursor.execute('select version(), current_date')
###
Hope this helps!