0

I have a DB and when I query a table I get 67 results. The SQL is:

SELECT lower(UserName) from Participants ;

I try to connect to the DB, and I get no connection errors.

def db_connect ():                                                                                                    
    try:                                                                                                              
        cnx = mysql.connector.connect(user=db_user, password=db_password,host=db_host,database=db_name)               
        return cnx                                                                                                    
    except mysql.connector.Error as err:                                                                              
        if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:                                                             
            print("Something is wrong with your user name or password")                                               
        elif err.errno == errorcode.ER_BAD_DB_ERROR:                                                                  
            print("Database does not exist")                                                                          
        else:                                                                                                         
            print(err)  

                                                                                                                      
def main():                                                                                                           
    cnx = db_connect()                                                                                                
    cursor = cnx.cursor()                                                                                             
    query = ("SELECT lower(UserName) from Participants ;")                                                            
    cursor.execute(query)                                                                                             
    print(cursor.rowcount)    

It prints out -1 for rowcount. The connection to the DB appears to be working, the SQL is a simple query...

1 Answer 1

1
  • Try adding cursor.fetchall() before the print(cursor.rowcount)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.