Tim Kiryachek
Tim Kiryachek

Reputation: 23

Problem with cursors of python mysql-connector

I faced a problem connected with mysql-connector in python. Inspite the database is connected successfully and connection's cursor is instance of mysql.connector.cursor.MySQLCursor, any actions with it like .execute() return None.

So query is the last line returns None. Are there any solutions?

import mysql.connector
with mysql.connector.connect(host='localhost',
    user='Tec',
    passwd='TecHeres3141',
    database='abiturients') as db:
    print(db.is_connected())
    cursor = db.cursor()
    print(type(cursor), cursor)
    print(cursor.execute('SELECT CURRENT_TIME();'))``` 

Upvotes: 1

Views: 1479

Answers (1)

BokiX
BokiX

Reputation: 508

You need to run this line of code: print(cursor.fetchall()) to get all data that you got with your cursor.execute(). For example if you are doing a simple SELECT * FROM table you need to use fetchall() to get all results and then print it. Also to apply changes to your database use db.commit().

Upvotes: 1

Related Questions