Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 12th, 2000, 11:54 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()


E-mail me: goodgoodtom@yahoo.com
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #2  
Old October 17th, 2000, 08:53 AM
batra batra is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 batra User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm not sure how the Mysql library for python works but your browser header should look exactly like this:

print "Content-type:text/htmlnn"


------------------
PB
Comments on this post
JimmyGosling agrees!

Reply With Quote
  #3  
Old November 27th, 2000, 03:39 AM
paxjesus paxjesus is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2000
Posts: 5 paxjesus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MySQL is correct mysql module name?
I use MySQLdb module.
in That case,
Examples likes)
import MySQLdb
connection = MySQLdb.connect(user='hyun',db='hyun')
cursor = connection.cursor()
query="select count(*) from pybbs"
cursor.execute(query)
RowNum=cursor.fetchone()

Then,
RowNum[0] has the result.
Comments on this post
JimmyGosling agrees!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > 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

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





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