我最近开始学习Python和MySQL的Web目的,我遇到了如下问题:
我想从包含我在参数部分输入任何文字MySQL数据库的一个记录拔出,howerver我遇到以下进行查询时的问题:
traceback (most recent call last):
File "/Users/Strielok/Desktop/test.py", line 13, in <module>
c.execute("SELECT * FROM data WHERE params LIKE ('%s%') LIMIT 1" % (param))
TypeError: not enough arguments for format string
这里是我的代码:
import MySQLdb
db = MySQLdb.connect (host = "localhost",
user = "root",
passwd = "root",
db = "test")
param = "Test"
par = param
c = db.cursor()
c.execute("SELECT * FROM data WHERE params LIKE ('%s%') LIMIT 1" % (param))
data = c.fetchall()
print data
c.close()
提前致谢。