Page 69 - Python Cơ Bản
P. 69
import MySQLdb
db = MySQLdb.connect(...)
cursor = db.cursor()
cursor.close()
db.close()
4VITEVIH 7XEXIQIRX
4VITEVIH WXEXIQIRX Pɧ Oц XLYϼX XLEQ WР LɹE GɨG Hо PMЖY
XVY]АR ZɧS GɩY XVY] ZϴR XLE] Zɳ RРM GLYЦM XVрG XMЎT чВ \ɩ]
HрRK QШX GLYЦM XVY] ZϴR HɧM /ц XLYϼX Rɧ] чвG ɨT HдRK
RLMАY Zɧ KMɾT XʆRK LMЖY UYϲ Zɧ XɴRL FϲS QϼX GжE GɩY XVY]
ZϴR :ɴ Hд
...
cur.execute("UPDATE Writers SET Name = %s WHERE Id
= %s", ("John", "4"))
...
1ЦM XLEQ WР XVY] ZϴR WЌ чвG XLE] XLЎ FЀRK %s Zɧ TLRK
XLиG execute() WЌ Gɹ XLEQ WР XLи Pɧ QШX 8YTPI Gɹ KMɨ XVК