Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import mysql.connector
- from mysql.connector import Error
- sql = """select now();"""
- try:
- connection = mysql.connector.connect(host='127.0.0.1', database='test', user='root', password='12345')
- if connection.is_connected() : print('Connected to MySQL database')
- except Error as e:
- print(e)
- with connection.cursor() as cursor:
- cursor.execute(sql)
- result = [row[0] for row in cursor]
- Connected to MySQL database
- Traceback (most recent call last):
- File "./test.py", line 16, in <module>
- with connection.cursor() as cursor:
- AttributeError: __exit__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement