[DB-SIG] Beginner getting out...

Turcotte, Paul paulturcotte@bbg.org
Wed, 20 Mar 2002 15:16:22 -0500


> Just give my an example (a simple one) of how to connect with MySQL and
add 
> something to a table. That would do. Once I get the idea I'll see how to 
> retrieve, modify, etc.


This FAQ may help you get started.

http://dustman.net/andy/python/MySQLdb_obsolete/faq/MySQLdb-FAQ-3.html

>From FAQ:

<snip>

Okay, it goes something like this:

   1. Import MySQLdb.
   2. Create a Connection object.
   3. Create a Cursor object.
   4. Execute your query on the Cursor object.
   5. If your query returns rows, you can use the Cursor object to fetch
them.
   6. Rinse, lather, repeat.

Example:

import MySQLdb
db = MySQLdb.connect(db='mydb',user='myuser',passwd='mypasswd')
c = db.cursor()
c.execute(myquery)
results = c.fetchall()

</snip>

Suerte,
PT