[Tutor] database connectivity over networks
Daniel Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 30 May 2001 00:58:47 -0700 (PDT)
On Tue, 29 May 2001, Curtis Horn wrote:
> I was wondering how I would go about sending data to a database over a
> network using python.
What sort of database is it? Is it MySQL, Postgres, or something else?
I'll assume that you mean an SQL database. Python uses a standardized
database interface (DB API 2.0), so the motions to set things up are
similar between database systems.
http://python.org/topics/database/DatabaseAPI-2.0.html
You'll need to start up a connection with the server, and this is usually
done with a connect() call. In MySQL, for example, if we wanted to
connect to a database in Tokyo, for example, we could do something like
this:
###
import MySQLdb
db = MySQLdb.Connection(host="database.monster.jp",
user="godzilla",
passwd="rubberducky",
db="GameraDefensePlans")
###
>From then on, we can do database stuff through our 'db' instance. So it
really shouldn't matter where the database is located after we initialize
our connection, be it overseas or in the middle of the Nevada desert.
Tell us a little more about what kind of database it is, and we can point
you toward relevant information. You can also find more information here:
http://python.org/topics/database/
Good luck to you.