Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1.  
  2. 3
  3. 4
  4. 5
  5. 6
  6. 7
  7. 8
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21.  
  22. import pymysql
  23.  
  24. # MySQL Connection 연결
  25. conn = pymysql.connect(host='localhost', user='tester', password='',
  26. db='testdb', charset='utf8')
  27.  
  28. # Connection 으로부터 Cursor 생성
  29. curs = conn.cursor()
  30.  
  31. # SQL문 실행
  32. sql = "select * from customer"
  33. curs.execute(sql)
  34.  
  35. # 데이타 Fetch
  36. rows = curs.fetchall()
  37. print(rows) # 전체 rows
  38. # print(rows[0]) # 첫번째 row: (1, '김정수', 1, '서울')
  39. # print(rows[1]) # 두번째 row: (2, '강수정', 2, '서울')
  40.  
  41. # Connection 닫기
  42. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement