#!/usr/bin/python
# e begoli, python connector for mysql
# import MySQL module
import MySQLdb

# connect
db = MySQLdb.connect(host = "localhost", user = "adamplo1", passwd = "U7RJM5HQ", db = "adamplo1_UniProject")

# create a database cursor
cursor = db.cursor()

# execute SQL select statement
cursor.execute("SELECT * FROM User")

# get the number of rows in the resultset
numrows = int(cursor.rowcount)

# get and display one row at a time
for x in range(0,numrows):
    row = cursor.fetchone()
    print row[0], "-->", row[1]

is there any error with the above script. I am running the scrip on an external hosting and you can see what i get here http://adamplowman.com/cgi-bin/database.py.

I am new to python and would appreciate any help

Recommended Answers

All 8 Replies

# execute SQL select statement
cursor.execute("SELECT * FROM User")

From what I know I think it was supposed to be this way
FROM user SELECT *

NO that has done nothing, any other ideas?

0 --> Adam

I don't see any errors? Your query syntax looks correct so what's the problem exactly?

You marked it solved, what did you exactly do? what was wrong??

Yeah i fixed it earlier on today and forgot about this thread.

Thanks

Please put resolution for benefit of others

oh ok,

as i was printing this out onto a web page i need to set a simple header, hear is the final version of the code

#!/usr/bin/python
# e begoli, python connector for mysql
# import MySQL module
import MySQLdb
# here is the new line to set a header
print "Content-type: text/html\n"
# connect
db = MySQLdb.connect(host = "localhost", user = "fghfghfghfg", passwd = "dgfdgdfghdfgh", db = "adamplo1_UniProject")

# create a database cursor
cursor = db.cursor()

# execute SQL select statement
cursor.execute("SELECT * FROM User")

# get the number of rows in the resultset
numrows = int(cursor.rowcount)

# get and display one row at a time
for x in range(0,numrows):
    row = cursor.fetchone()
    print row[0], "-->", row[1]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.