简体   繁体   中英

MySQL python connector returns empty result on select query

I am trying to fetch a result from my database table users, using the cursor.execute() statement but when I try to execute the program, I get an empty result. Here's the code

import mysql.connector as mysql; mycon=mysql.connect(host="localhost",user="root",passwd="12345",database="Markwiss") cursor =mycon.cursor() cursor.execute("select*from users;")

I recently updated both python and mysql to the latest versions and since then I have been facing this problem. I have tried executing some other statements like INSERT INTO, DELETE FROM, and they have been working fine.

Looks like you're executing the query but not reading it. Try adding the following:

result = cursor.fetchall()

then you can access each line of the query with a for loop:

for line in result:
        #do something ```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM