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

#!/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:python

Number of rows updated: 1
相關文章
相關標籤/搜索