MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 12th, 2000, 11:51 PM
harley harley is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: HK
Posts: 6 harley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am a master student in Australia and trying to do a project - website - about accessing MySQL database in Linux platform with Python/CGI script through webpage, but the python codes didn't work.

Do you know how to do it? Can you give us some sample codes?

I have two python files as follows, can you check them what are wrong?

1)

#!/usr/bin/python
import cgi
import mysql

database = 'bestuni'
query = 'SELECT * FROM uni'

dbh = MySQL.connect('localhost', 'root', 'mypassword')
dbh.selectdb(database)

result = dbh.do(query)

print "Content-type: text/htmlrnrn"
print "<html><head><title>Python Bestuni</title></head><body>n"
for row in result:
print "Best Universities =", row[0], ", desc=", row[1], ", widgetid=", row[2], "<p>"
print "</body></html>n"

dbh.close()

2)

#!/usr/bin/python
import cgi
import pickle
import MySQL

def uni():
print "Content-type:text/htmln"
print '<html>'
print "<head><title> Harley's uni cgi</title></head>"
print '<body>'
print '<form method="POST" action="http://ip54200.scu.edu.au/harley-cgi/uni.py">'
print '<p><center><h1>The best universities around the world</h1></center></p>'
print '<p><center><h2>Do you know the best universities over the world?</h2></center></p>'
print '<p><center><input type="submit"name="yes" value="Yes"></center></p>'
print '<p><center><input type="submit"name="no" value="No"></center></p>'
print '</form>'
form=cgi.FieldStorage()
f=open("bestuni.mysql","r")
data=pickle.load(f)
f.close()
if form.has_key("new"):
print "<b>The best universities around the world are as follows:</b>"
print data[rank],data[name],data[country],data[e_mail]
elif form.has_key("no"):
print "<p>Wow, man! You don't want to those things? mmm...</p>"
f.close()
print "</body>"
print "</html>"

uni()


Pls e-mail me: goodgoodtom@yahoo.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > How to access MySQL with Python?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway