Page 65 - Python Cơ Bản
P. 65
import MySQLdb
db = None
try:
db = MySQLdb.connect(host = 'localhost', user =
'root', passwd = 'root', db = 'mysql')
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
if db:
cur = db.cursor()
cur.execute("SELECT VERSION()")
ver = cur.fetchone()
print "Database version : %s " % ver
/ЎX RРM ZЪM charset utf8
1ІG чКRL OЎX RРM чЎR 1]750 WIVZIV Pɧ GLEVWIX latin RɱR
OLM Pϴ] Hо PMЖY YRMGSHI XLɳ LMВR XLК 8MЎRK :MЖX OLɺRK чɾRK
FϰR G϶R TLϲM GLМR GLEVWIX Pɧ utf8 OLM XϰS OЎX RРM 'ɾ TLɨT
RL WEY