Can anyone help me to connect the mysql with python-CGI.
I tried it. but it doesn't work.
please help me.
I tried it. but it doesn't work.
please help me.
#!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/>"
#!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)
#!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/>"
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
#!C:\Python25\python.exe print "Content-Type: text/html\n\n" print "hello"
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
#!C:\Python25\python.exe print "Content-Type: text/html\n\n" print "hello"
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/>
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/>
Comment