Guest User

Untitled

a guest
Jun 17th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. connection = pymysql.connect(host='localhost',
  2. user='root',
  3. password='password',
  4. db='blog',
  5. charset='utf8',
  6. cursorclass=pymysql.cursors.DictCursor)
  7.  
  8.  
  9. with connection.cursor() as cursor:
  10. # Read a single record
  11. sql = "SELECT * from categories"
  12. cursor.execute(sql)
  13. result = cursor.fetchall()
  14. print(result)
  15. connection.close()
  16.  
  17. #do other thins ..............................
  18. #maby return here and do not execute below
  19. #occur error below
  20.  
  21. with connection.cursor() as cursor:
  22. # Read a single record
  23. sql = "SELECT * from categories"
  24. cursor.execute(sql)
  25. result = cursor.fetchall()
  26. print(result)
Add Comment
Please, Sign In to add comment