faqts : Computers : Programming : Languages : Python : Snippets

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 2 people (50%) answered Yes
Recently 1 of 2 people (50%) answered Yes

Entry

How do i connect to a database in Unix using python

Aug 13th, 2001 14:24
Christopher Arndt, Asfar Sayeed,


For this purpose, we have the Python Database API Specification 2.0
For general information see http://www.python.org/sigs/db-sig/
There are a whole bunch of modules for specific database systems that 
conform to this specification (or version 1.0 thereof)
For a list see http://www.python.org/topics/database/modules.html
In short, you use them like this:
import dbmodule
cnx = dbmodule.connect(database='test') # there are a lot more
					# parameters possible
cur = cnx.cursor()
cur.execute('SELECT * from table')
result_list = cur.fetchall()
# You now have a list of ros in result_list
cur.close()