It might seem intimidating, but hooking Zope up to a MySQL database is easier than you think. And once you've got the two talking nice to each other, it becomes even simpler to create dynamic, Zope-based Web applications. Take a look.
With Zope and MySQL now talking to each other, it's time to start actually doing something with them. Here's the MySQL table I'll be using throughout this article - it stores information on my DVD collection.
CREATE TABLE dvd (
id int(10) unsigned DEFAULT '0' NOT NULL,
cast varchar(255) NOT NULL,
director varchar(255) NOT NULL,
genre varchar(255) NOT NULL
INSERT INTO dvd VALUES ( '1', 'Don't Say A
Sean Bean and Brittany Murphy', 'Gary Fleder', 'Suspense');
INTO dvd VALUES ( '2', 'Captain Corelli's Mandolin', 'Penelope
Cruz and Nicolas
Cage', 'John Madde', 'Romance');
Now, the second step in getting Zope to communicate with this database involves
creating an instance of the Z MySQL Database Connection object. You can create one of these via Zope's management interface; when you do, you'll see something like this:
At this point, it's necessary to specify a database connection string, so that Zope can open a connection to the database. This string is usually of the form:
So, if I wanted to set up a connection to the database "mystuff" for user "john"
with password "secret", my connection string would look like this:
mystuff john secret
Once you've created the Connection object, you can test it via the Test function
that appears within the Zope management interface. This function allows you to execute any SQL query on the database, and returns the result to you instantly. Try executing the query
SELECT * FROM dvd
and see what happens. If your screen fills up with data, it means that your database
connection is working just fine.
Once a Database Connection object has been created, it's possible to instantiate Z SQL Methods to execute queries via this connection (I'll be doing this over the next few pages).