DB-API-oriented example scripts?

sp00fD sp00fD at yahoo.com
Fri Dec 10 09:16:22 EST 1999


In article <199912100620.AAA22933 at dolphin.mojam.com>,
  skip at mojam.com (Skip Montanaro) wrote:
>
> I'm gearing up to try and replace a lot of homegrown database code
with
> MySQL using the MySQLdb module.  I'm not much of a relational database
> person, however, so I'm fairly unfamiliar with the computational model
> expected by the Python DB API.  I can muddle my way through SQL.  The
> MySQLdb module comes with no example code as far as I could tell
however,
> and relies heavily on the 2.0 version of the Python DB API spec for
docs,
> which contains no examples.
>
> Are there any good examples of how to use this API available?  I saw a
> reference to a Linux Journal article on the db sig's page which I
will take
> a look at.  I saw nothing that looked like pointers to example code
in the
> Vaults of Parnassus.
>
> Any suggestions?
>
> Thx,
>
> Skip Montanaro | http://www.mojam.com/
> skip at mojam.com | http://www.musi-cal.com/
> 847-971-7098   | Python: Programming the way Guido indented...
>
>

I had the same problem, I wish the Python documentation was a little
better as a whole.  Anyway, here's the basics:

import MySQLdb
foo = MySQLdb.connect(host=localhost,db=Mydb,user=user,passwd=passwd)
bar = foo.cursor()

sql = "SELECT * from Mytable"
bar.execute(sql)
rs = bar.fetchall()    # returns a list
foo.close()


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list