我正在研究python并试图从Mysql数据库中获取一些数据,下面是查询
import MySQLdb as mdb
page = 1
perpage = 3
offset = (int(page) - 1) * perpage
conn = mdb.connect(user='root', passwd='redhat', db='Python_Web', host='localhost')
cursor_posts = conn.cursor()
posts = "select * from projects LIMIT = %s OFFSET = %s " %(offset,perpage)
cursor_posts.execute(posts)
错误:
^{pr2}$有人能告诉我上面的问题是什么吗, 实际上,我试图用python实现分页网页.py框架
我相信这应该只是
LIMIT %s OFFSET %s
。没有等号。在限制和偏移都没有使用
=
等于符号,所以您的SQL确实不正确。在您确实应该使用SQL参数,其中数据库库引用您的值并防止SQL注入攻击:
请注意参数的顺序;
LIMIT
排在第一位,所以先传入perpage
参数。在您只需使用:
^{2}$同样,将
OFFSET
替换为逗号,交换参数。在相关问题 更多 >
编程相关推荐