Reputation: 3
ANY query passed through yields "None" result:
import mysql.connector
config = {
'host': 'localhost',
'user': 'root',
'password': '',
'raise_on_warnings':True
}
conn = mysql.connector.connect(**config)
csr = conn.cursor()
result = csr.execute('SHOW DATABASES')
print(result)
Result:
None
Upvotes: 0
Views: 155
Reputation: 361
You are missing the fetchall()
method as written here.
(Also you are not giving any database).
csr.execute(some_query)
does not return any value. This method just change is own value, and you can collect it calling csr.fetchall()
, that returns a list of tuples that you can iterate with a for loop or using whatever way you want.
import mysql.connector
config = {
'host': 'localhost',
'user': 'root',
'password': '',
'database': 'database_name',
'raise_on_warnings': True
}
conn = mysql.connector.connect(**config)
csr = conn.cursor()
csr.execute('SELECT * FROM some_table_of_given_database')
result = csr.fetchall()
print(result)
conn.close()
Upvotes: 1