[DB-SIG] retrieve data from mysql

ronald lam ronald at hondabutton.com.hk
Thu Nov 27 21:53:46 EST 2003


I'm a newbie, I want to retrieve data from mysql server, all are normal 
but non of datas could retrieve from database, it is because wrong 
select syntags as below:

cursor.execute("SELECT descrip, pri, unit FROM code where descrip like 
'%$siz%' limit 20")

Will any Masters help me fixing the sentence '%????%'

Rgds

-------------------------------------

#!/usr/local/bin/python

# import MySQL module
import MySQLdb

# get user input
siz = raw_input("Please enter size: ")
#des = raw_input("Please enter description: ")

# connect
db = MySQLdb.connect(host="fa", user="ron", passwd="xxxxx",
db="hon")

# create a cursor
cursor = db.cursor()

# execute SQL statement
#cursor.execute("INSERT INTO animals (name, species) VALUES (%s, %s)",
#(name, species))

cursor.execute("SELECT descrip, pri, unit FROM code where descrip like 
'%$siz%' limit 20")
result = cursor.fetchall()
for record in result:
	print record[0],'--->', record[1], record[2]




More information about the DB-SIG mailing list