|
Trevor Hennion
trevor at thennion.demon.co.uk
Sat Oct 30 05:22:17 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Friday 29 Oct 2004 23:34, Robert Geller wrote:
> Hello all --
>
> I am having trouble with mod_python 3.1.3 and MySQLdb 1.1.6 (recommended
> by the Andy, the author of MySQL-db).
> I'm just trying to get this to work, and have a test page setup, with a
> mysql query and fetchall statement as follows:
>
>
> from mod_python import apache
> import MySQLdb
>
> def handler(req):
> req.content_type = "text/html"
> req.write("Hello World!")
>
> db = MySQLdb.connect('localhost', 'root', 'tux5098nyu',
> db='imagehost')
> c = db.cursor()
> c.execute("select * from users;")
> results = c.fetchall()
>
> return apache.OK
>
>
> Now, I can't tell if the query is executing. I get NO errors from Mod
> Python (debugging is on), but it only displays "Hello world!" in the
> browser, as opposed to the results of the query rom my c.fetchall()
> statement. I have tried it in the Python interactive shell, and it works
> perfectly. I just can't tell why it won't display the query here.
>
> I have also tried it in a separate function, as follows:
>
>
> def mysql(req):
>
> db = MySQLdb.connect('localhost', 'root', 'tux5098nyu',
> db='imagehost')
> c = db.cursor()
> c.execute("select * from users;")
> results = c.fetchall()
> return results
>
> but to no avail.
>
> Thanks for your help.
>
>
>
> Robert Geller
>
> robert at worksofmagic.com
Robert,
I'm not an expert at mod_python - in fact I find it quite confusing! but
looks to me like you have the data in 'results', but you aren't doing anything
with it - at least not in the code you have posted.
Try:
req.write(results)? or even
print "Results are:", results
HTH
Regards
Trevor Hennion
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQFBg11SH6bp7SfUeAARApCqAJwMmCHCk6pdvLSVVwVtqSSjlHEe2ACdGeqR
yFxOy3C7CC3+o/vgkGlzJsc=
=Dw2t
-----END PGP SIGNATURE-----
|