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

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState