[Zope-DB] Python script in Zope
Tue, 03 Dec 2002 23:19:09 +0100
On 2002-12-03 at 23:00:21 [+0100], firstname.lastname@example.org wrote:
> I've got the following Python script:
> # Example code:
> This works well on the Python interpreter console.
you don't need to access the database like that in Zope. Just create a
database connection object, create a ZSQL method which uses that object and=
call that method from a PythonScript, PageTemplate or DTML - try using a
Z-SearchInterface to see how this works.
> db =3D MySQLdb.connect(host=3D"localhost", user=3D"root", passwd=3D"secre=
use this in your connection object
> cursor =3D db.cursor()
don't need this
> cursor.execute("SELECT * FROM books")
Put SELECT * FROM books in your ZSQL method "qBooks" or similar
> result =3D cursor.fetchall()
> for record in result:
> print record, "-->", record
don't need the rest.
results =3D context.qBooks()
=09for result in results:
But that is not what you want to do.
<p tal:repeat=3D"result here/qBooks" tal:content=3D"result/...">put the res=
of the query here but you need to know the names of the columns</p>