Advertisement
Guest User

Untitled

a guest
May 21st, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import mysql.connector
  4. from mysql.connector import Error
  5.  
  6. sql = """select now();"""
  7.  
  8. try:
  9. connection = mysql.connector.connect(host='127.0.0.1', database='test', user='root', password='12345')
  10. if connection.is_connected() : print('Connected to MySQL database')
  11. except Error as e:
  12. print(e)
  13.  
  14. with connection.cursor() as cursor:
  15. cursor.execute(sql)
  16. result = [row[0] for row in cursor]
  17.  
  18. Connected to MySQL database
  19. Traceback (most recent call last):
  20. File "./test.py", line 16, in <module>
  21. with connection.cursor() as cursor:
  22. AttributeError: __exit__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement