Python don't register in MySQL server
Question: there’s something wrong in my python script: when I try to put some data in my
database and print it, it looks like it’s working, but when I rerun the code,
or if I check the phpmyadmin, there’s no data saved in the db. Does anyone
have some idea on how to solve this problem?

    
    
    import mysql.connector
    from mysql.connector import errorcode
    
    
    def connect():
        """ Connect to MySQL database """
        try:
            conn = mysql.connector.connect(host='localhost',
                                           database='Temperature',
                                           user='Temperature',
                                           password='mypass')
            if conn.is_connected():
                print('Connected to MySQL database')
                cur = conn.cursor()
    
                query = "INSERT INTO Temp(temp, humi) " \
                "VALUES(315, 55)"
                try:
                    cur.execute(query)
                except MySQLdb.ProgrammingError as e:
                    print(e)
    
                query = "SELECT * FROM Temp"
                try:
                    cur.execute(query)
                    for reading in cur.fetchall():
                        print (str(reading[0])+"    "+str(reading[1]))
                except MySQLdb.ProgrammingError as e:
                    print(e)
    
        except Error as e:
            print(e)
    
        finally:
            conn.close()
    
    
    if __name__ == '__main__':
        connect()
    


Answer: You will need to add `conn.commit()` before `conn.close()`. That should solve
the problem.

