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.
So that takes care of adding records. Now, how about deleting them?
You'll remember, from the "list" DTML Method created at the beginning of this exercise, that every item in the DVD list has links pointing to "edit" and "delete" objects, and that these objects are passed the record ID of the corresponding item.
So, in other words, the "delete" object - another DTML Method - needs simply
to use this ID to execute a DELETE query on the table. Let's take a look at the code for this DTML Method:
<dtml-var standard_html_header>
<dtml-call deleteMethod>
<h2>Item
deleted!</h2>
<p>
<a href="list">View the entire collection</a>
or <a href="add">add
another title</a>
<dtml-var standard_html_footer>
No biggie. Like the "add" DTML Method before it, this one too simply functions
as a wrapper for a Z SQL Method, which actually does all the work. In this case, the Z SQL Method is named "deleteMethod" and it receives a record ID as argument. Let's see what that looks like:
DELETE FROM dvd WHERE id = <dtml-sqlvar id type="int">
The "deleteMethod" Z SQL Method contains a simple DELETE query, with the record
ID passed to it inserted dynamically into the query template.