python mysql 参数化查询_python3中使用MySQLdb的参数化查询

MySQL Python项目不支持python3-see the project web page,它多年来一直说“python3支持很快就会到来”,而{a2}只提供python2.7版本,并说:Python-3.0 will be supported in a future release.

据我所知,没有可用的“-py3.2”发行版(或者可以通过搜索找到);您的主机可能有一些愚蠢的东西(例如this)来让库安装在Python3上,但是能够安装库并不能保证它能够实际工作。在Today i switched to Python v3.2.3 on my remote web server at

HostGator. My cgi-script which it works at python v2.6.6 now produces

theses errors:> >

Traceback (most recent call last):

File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 171, in execute

r = self._query(query)

File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 330, in _query

rowcount = self._do_query(q)

File "/opt/python3/lib/python3.2/site-packages/MySQL_python-1.2.3-py3.2-linux-x86_64.egg/MySQLdb/cursors.py", line 294, in _do_query

db.query(q)

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1")

关于%s语法对于库来说是正确的;不幸的是,它在python3中的表现并不好。您可以尝试使用命名参数样式,看看这是否能让您有所收获,但最好的办法是完全停止使用不受支持的库。例如,如果您的主机还提供an old version of Connector/Python。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值