您的位置:首页 > 其它

Instance Six:使用Prepared statements执行查询(更安全方便)

2016-01-05 15:48 357 查看
#!/usr/bin/env python
#--*-- coding:utf-8 --*--
__author__ = 'Kevin'

import MySQLdb as mdb
import sys

con = mdb.connect('localhost','root','redhat','test')

try:
with con:
cur = con.cursor()
cur.execute("UPDATE Writers SET Name = %s WHERE Id = %s",("Guy de Maupasant","3"))
print "Number of rows updated: %d" % cur.rowcount
finally:
con.close()


Result:

Number of rows updated: 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: