Zope And MySQL - Adapting To The Environment (
Page 3 of 9 )
Normally,
setting up a connection between Zope and an external RDBMS like MySQL, Oracle,
PostgreSQL or even Gadfly requires two things: a Database Connection object, which
is used to perform communication between Zope and the specified database, and
one or more Z SQL methods, which are used to execute queries on the database.
Zope comes with adapters for a variety of different databases, including ODBC,
Oracle, MySQL and Interbase. I'll be connecting Zope to a MySQL database in this
article; however, the process is similar for other database systems.
Hooking Zope up to MySQL is a little tedious, especially if you attempt to do
it solely on the basis of the information available online. This is because much
of the online documentation relating to Zope-MySQL connectivity is outdated and
no longer relevant, and you can lose a whole day just trying out different variants
of the techniques suggested. So let me make it as simple as possible.
Getting Zope and MySQL to talk nice to each other requires you to install the
following two pieces of software:
1. The Zope MySQL Database Adapter (ZMySQLDA), available from http://www.zope.org/Members/adustman/Products/ZMySQLDA
2. The Python MySQL Database Interface (MySQLdb), a Python MySQL driver available
from
http://www.zope.org/Members/adustman/Products/MySQLdb
You can also find this software at
http://sourceforge.net/projects/mysql-python
The installation process is fairly simple.
1. Install (copy) the ZMySQLDA files into Zope's Products directory (usually
<Zope>/lib/python/Products).
2. Extract the MySQLdb files to the same place. Configure and compile the driver
(instructions are available in the source archive) using the Python binary that
shipped with your version of Zope. This is extremely important, because if you
don't use the exact binary that ships with your Zope installation, Zope won't
know how to handle the driver.
3. Install the compiled driver into your Zope build (again, instructions to accomplish
this are available in the driver's documentation).
4. Restart Zope.
This process works on Linux; however, despite my best efforts, I was unable to
get Zope and MySQL talking on Windows. It's certainly possible, though, and the
process is about the same - take a look at http://zope.org/Members/philh/ZMySQLDA_html
for some hints.
Assuming all goes well, you should now see a new Z MySQL Database Connection
object type in the Type drop-down list within the Zope management interface.
If you don't see this item, it usually means that something bad happened during
the installation process. Drop by
http://www.zope.org/Members/alanpog/zmysqlda_steps and see what you did wrong.