Home arrow Zope arrow Page 4 - Zope And MySQL

The Magic Of The Movies - Zope

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.

TABLE OF CONTENTS:
  1. Zope And MySQL
  2. Making The Connection
  3. Adapting To The Environment
  4. The Magic Of The Movies
  5. Visiting The Box Office
  6. Adding Things Up
  7. Submitting To The King
  8. Erasing The Past
  9. Of Methods And Madness
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 27
April 10, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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, title varchar(255) 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 Word', 'Michael Douglas, Sean Bean and Brittany Murphy', 'Gary Fleder', 'Suspense'); INSERT 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:

database[@host[:port]] [user [password [unix_socket]]]
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).

 
 
>>> More Zope Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

ZOPE ARTICLES

- Creating Zope Products
- Plone Content Types With Archetypes
- Flat User Management in Zope
- Creating Basic Zope Applications
- Getting started with Zope for Linux and Sola...
- ZPT Basics (part 4)
- ZPT Basics (part 3)
- ZPT Basics (part 2)
- ZPT Basics (part 1)
- Exception Handling In DTML
- DTML Basics (part 4)
- DTML Basics (part 3)
- DTML Basics (part 2)
- DTML Basics (part 1)
- Using Zope With Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: