Page 66 - Python Cơ Bản
P. 66

...

           db = MySQLdb.connect(host = 'localhost', user = 'ro

           ot', passwd = 'root', db = 'test', charset = 'utf8'

           )





               5YIV] Hо PMЖY







          ɇВ XVY] ZϴR Hо PMЖY  GLϰ] GɩY PЖRL 750  XLɳ Wм HдRK  cursor

          GжE 1]750HF  :ɴ Hд





           import MySQLdb



           db = MySQLdb.connect(host = 'localhost', user = 'ro

           ot', passwd = 'root', db = 'mysql');

           cursor = db.cursor()

           sql = 'SELECT * FROM user'

           cursor.execute(sql)

           myusers = cursor.fetchall()







          :ɴ Hд Hо PMЖY FMЎR  myusers  Pɧ   ((1, 'John'), (2, 'Doe'))



          1ІG чКRL   cursor  WЌ XVϲ ZА QЦM HɸRK Hо PMЖY Xк 1]750


          XLIS OMВY  tuple   XиG Pɧ OLɺRK Gɹ OI]  2ЎY FϰR QYРR XVϲ ZА
   61   62   63   64   65   66   67   68   69   70   71