Can anyone help me to connect the mysql with python-CGI.
I tried it. but it doesn't work.
please help me.
18 4194
Can anyone help me to connect the mysql with python-CGI.
I tried it. but it doesn't work.
please help me.
as usual, help us to help you by providing as much info as you can, like when you said cannot work, what exactly cannot work. Errors you encountered, provide the code that you have done and describe your expected results, etc etc
Can anyone help me to connect the mysql with python-CGI.
I tried it. but it doesn't work.
please help me.
Ghostdog is right. There are posting guidelines which state that you must describe what your trouble is AND give examples of what you have done to get to this point. "I tried it. but it doesn't work." doesn't give us anything to go in in terms of helping you solve your problem.
i myself working on mysql and cgi-python for a project assigned to me. if you don't mind i'll post my codes here and you can try to see it.
i myself working on mysql and cgi-python for a project assigned to me. if you don't mind i'll post my codes here and you can try to see it.
Yes. Please post you code.
Apologize!!!!!!!!!!!!!!!!!!
Here is my code...
It is not working...but when i connect mysql in standalone python code, it's working...
Please check my code and reply...
thanks.. -
#!C:\Python25\python.exe
-
-
print "Content-type: text/html\n\n"
-
import sys
-
import MySQLdb
-
-
try:
-
conn = MySQLdb.connect(host="localhost",user="root",passwd="sudhakar",db="test");
-
print "Connected<br/>"
-
except:
-
print "Cannot connect to server.</br>"
-
sys.exit(1)
-
-
try:
-
cursor = conn.cursor()
-
cursor.execute("SELECT * FROM sudha");
-
rows = cursor.fetchall()
-
for row in rows:
-
print "%s: %s, %s<br/>" % (row[0],row[1],row[2])
-
print "%d rows were returned<br/>" % cursor.rowcount
-
cursor.close()
-
except MySQLdb.Error, e:
-
print "query failed<br/>"
-
print e
-
-
conn.close()
-
print "Disconnected<br/>"
sorry, now it's in code tag:- - #!C:\Python25\python.exe
-
-
print "Content-type: text/html\n\n"
-
import sys
-
import MySQLdb
-
-
try:
-
conn = MySQLdb.connect(host="localhost",user="root",passwd="sudhakar",db="test");
-
print "Connected<br/>"
-
except:
-
print "Cannot connect to server.</br>"
-
sys.exit(1)
-
-
try:
-
cursor = conn.cursor()
-
cursor.execute("SELECT * FROM sudha");
-
rows = cursor.fetchall()
-
for row in rows:
-
print "%s: %s, %s<br/>" % (row[0],row[1],row[2])
-
print "%d rows were returned<br/>" % cursor.rowcount
-
cursor.close()
-
except MySQLdb.Error, e:
-
print "query failed<br/>"
-
print e
-
-
conn.close()
-
print "Disconnected<br/>"
-
sys.exit(0)
Apologize!!!!!!!!!!!!!!!!!!
Here is my code...
It is not working...but when i connect mysql in standalone python code, it's working...
Please check my code and reply...
thanks.. -
#!C:\Python25\python.exe
-
-
print "Content-type: text/html\n\n"
-
import sys
-
import MySQLdb
-
-
try:
-
conn = MySQLdb.connect(host="localhost",user="root",passwd="sudhakar",db="test");
-
print "Connected<br/>"
-
except:
-
print "Cannot connect to server.</br>"
-
sys.exit(1)
-
-
try:
-
cursor = conn.cursor()
-
cursor.execute("SELECT * FROM sudha");
-
rows = cursor.fetchall()
-
for row in rows:
-
print "%s: %s, %s<br/>" % (row[0],row[1],row[2])
-
print "%d rows were returned<br/>" % cursor.rowcount
-
cursor.close()
-
except MySQLdb.Error, e:
-
print "query failed<br/>"
-
print e
-
-
conn.close()
-
print "Disconnected<br/>"
After I added code tags (which you will learn to do as we go along), I see a nasty indentation error at the top of the second try block. Are you getting something like syntax or indentation error? Will you paste the error here?
Hi barton..
the line cursor = conn.cursor() is in right position only.. there is no identation error... i pasted it correctly..but that line moved one tab. I dont know why? But in my code it is in right position only..
I am not getting any thing in the browser page, when i run this program...
It's plain.... -
try:
-
cursor = conn.cursor()
-
cursor.execute("SELECT * FROM sudha");
-
rows = cursor.fetchall()
-
for row in rows:
-
print "%s: %s, %s<br/>" % (row[0],row[1],row[2])
-
print "%d rows were returned<br/>" % cursor.rowcount
-
cursor.close()
-
except MySQLdb.Error, e:
-
print "query failed<br/>"
-
print e
Hi barton..
I am not getting any thing in the browser page, when i run this program...
It's plain....
Well, I see a database connection and some printing stdout, but I don't see any browser connection here. Do you know if your CGI redirects stdout?
Actually,I am using apache 2.2 server. so i will store the programs in apache-cgi-bin. then i will run that program in browser using the cgi-bin path.
In is simple cgi program...
we r not giving any specified browser path. - #!C:\Python25\python.exe
-
print "Content-Type: text/html\n\n"
-
print "hello"
like that..i am testing to connect the mysql...
Hi barton..
the line cursor = conn.cursor() is in right position only.. there is no identation error... i pasted it correctly..but that line moved one tab. I dont know why? But in my code it is in right position only..
I am not getting any thing in the browser page, when i run this program...
It's plain.... -
try:
-
cursor = conn.cursor()
-
cursor.execute("SELECT * FROM sudha");
-
rows = cursor.fetchall()
-
for row in rows:
-
print "%s: %s, %s<br/>" % (row[0],row[1],row[2])
-
print "%d rows were returned<br/>" % cursor.rowcount
-
cursor.close()
-
except MySQLdb.Error, e:
-
print "query failed<br/>"
-
print e
Except for the strange indentation, this looks perfectly fine to me. Have you tried running this under python using an IDE or otherwise where the window will stay open long enough to read the messages?
Actually,I am using apache 2.2 server. so i will store the programs in apache-cgi-bin. then i will run that program in browser using the cgi-bin path.
In is simple cgi program...
we r not giving any specified browser path. - #!C:\Python25\python.exe
-
print "Content-Type: text/html\n\n"
-
print "hello"
like that..i am testing to connect the mysql...
Did you see this thread?
I don't know whether my python-cgi code is correct or not...
you people have to say!!!!!!!!!!
Because i am beginner, just now started to program in cgi..
This is the output, i am getting when i run it in IDLE. - Connected<br/>
-
sudhakar: srf<br/>
-
4 rows were returned<br/>
-
anand: scientist<br/>
-
4 rows were returned<br/>
-
ramesh: jrf<br/>
-
4 rows were returned<br/>
-
ren: trainee<br/>
-
4 rows were returned<br/>
-
Disconnected<br/>
I don't know whether my python-cgi code is correct or not...
you people have to say!!!!!!!!!!
Because i am beginner, just now started to program in cgi..
This is the output, i am getting when i run it in IDLE. - Connected<br/>
-
sudhakar: srf<br/>
-
4 rows were returned<br/>
-
anand: scientist<br/>
-
4 rows were returned<br/>
-
ramesh: jrf<br/>
-
4 rows were returned<br/>
-
ren: trainee<br/>
-
4 rows were returned<br/>
-
Disconnected<br/>
So your MySQL connection is working correctly and the problem is in your CGI code. There must be some way to tell it where to direct the output that is being sent to stdout, but I don't know cgi.
Ok barton..No problem....
in apache there is a folder called "www"....for me i save my html page there and under this html page there should be a form such as like this: -
<form action='http://username/cgi-bin/cgi-script' method ='post/get'>
-
where the cgi-script is the cgi you wrote for your html.... did you configured your apache server? cgi script will be stored in the cgi-bin folder.
with this it should work since your database has no prob.... try thing.
sorry there was an error in the previous wan...i hv corrected it here....
in apache there is a folder called "www"....for me i save my html page there and under this html page there should be a form such as like this: -
<form action='http://host/cgi-bin/cgi-script' method ='post/get'>
-
where the cgi-script is the cgi you wrote for your html.... did you configured your apache server? cgi script will be stored in the cgi-bin folder.
with this it should work since your database has no prob.... try thing.
Did you configure Apache yourself as well? Out of the box it probably doesn't recognize a .py as cgi script unless you got some special build.
I only ask because you mentioned the output was "just plain" in a previous post. This thread is rather old so I will wait before explaining >.<
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bill Eldridge |
last post by:
I'm trying to grab a document off the Web and toss it
into a MySQL database, but I keep running into the
various encoding problems with Unicode (that aren't
a problem for me with GB2312, BIG 5,...
|
by: Josh |
last post by:
Hi,
First off, I am a newbie to Python and so far I must say that we're
getting along pretty well. My schooling was is C/C++, but have been
writing code in, dare I say it, VB, for the past 4...
|
by: Alec Wysoker |
last post by:
I need to be able to access mySQL 4.0 and 4.1 databases from python. I
was hoping to find mysql-python 1.2.0 already built for Sparc, but no
such luck. I've been struggling trying to get it...
|
by: grumfish |
last post by:
I'm trying to add a row to a MySQL table using insert. Here is the code:
connection = MySQLdb.connect(host="localhost", user="root", passwd="pw",
db="japanese")
cursor = connection.cursor()...
|
by: francescomoi |
last post by:
Hi.
I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2:
----------------------------------
# export PATH=$PATH:/usr/local/mysql/bin/
# export mysqlclient=mysqlclient_r
# python setup.py...
|
by: Mark Adams |
last post by:
I am a relative newbie to MySQL. I had a Postfix+Courier+MySQL mail
server running for several months. It took me a week or so to get it up
and running in September. Now, I did a clean upgrade to...
|
by: Roopesh |
last post by:
Hi,
In my mod_python project I am using mysql as the database. There is
table card in which unique cards are stored. When a user request comes
he has to get a unique card. In this situation I want...
|
by: coldpizza |
last post by:
Hi,
I want to run a database query and then display the first 10 records
on a web page. Then I want to be able to click the 'Next' link on the
page to show the next 10 records, and so on.
My...
|
by: Andrey |
last post by:
Hi
just a quick question about using MySQL module... are there any api / class
available to give a higher level in working with Mysql in python?
such as
db.fetch_array(),
db.fetch_rows(),...
|
by: marexposed |
last post by:
I've got this error (see the path in last line)
db=MySQLdb.connect(host='localhost',use_unicode = True, charset = "Windows-1251",user='root',passwd='12',db='articulos')
File...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |