Using Python to Query MySQL over the Net

Mihai shows how Python can be used to create a CGI script to enable elegant searching.
Conclusion

Python is a wonderful language. The MySQL module makes it easy to create small programs to retrieve data from a MySQL database. Python is also great for CGI scripting. Thus, having a database available to study through the web browser is just several lines of code away.

The application I have shown here is rather limited. The user can only search for five variables and in a fixed way, predetermined by the HTML form. However, it is conceivable for the user to write his or her own database queries through a textarea input field and view the query results on-line. In fact, the possibilities are limited only by the programmer's imagination.

Resources

Mihai Bisca, (AKA 5dan), is a former winner of the Romanian Go Championship. He spends countless hours playing with his Slackware Linux and dreams of working over the Internet from home. In his other, daytime life, he works as an ophthalmologist.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Python CGI script -> MySQL database tables retrieving

Sampath Girish's picture

Hi Mihai Bisca,
This is sampath. I am trying to retrieve tables from database usng Python CGI scripts and MySQL as backend. I am able to display an empty web page and unable to get the tables from database.
Its not displaying a line 'Hi' which i kept after

import MySQLdb
import cgi, Cookie

print 'HI'

I ran this along with script for retrieving tables in database in IDLE. It ran successfully. But now its unable to display in web browser. How can i do that?

please send me the reply to my email id if possible. Its girishmsampath@gmail.com

Geek Guide
The DevOps Toolbox

Tools and Technologies for Scale and Reliability
by Linux Journal Editor Bill Childers

Get your free copy today

Sponsored by IBM

Webcast
8 Signs You're Beyond Cron

Scheduling Crontabs With an Enterprise Scheduler
On Demand
Moderated by Linux Journal Contributor Mike Diehl

Sign up now

Sponsored by Skybot