-
-
Save parzibyte/f520e69dcb44b862c5f9e3014ecdacdd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymysql | |
try: | |
conexion = pymysql.connect(host='localhost', | |
user='root', | |
password='', | |
db='peliculas') | |
try: | |
with conexion.cursor() as cursor: | |
consulta = "UPDATE peliculas SET titulo = %s WHERE id = %s;" | |
nuevo_titulo = "Ready Player One: comienza el juego" | |
id_editar = 2 | |
cursor.execute(consulta, (nuevo_titulo, id_editar)) | |
# No olvidemos hacer commit cuando hacemos un cambio a la BD | |
conexion.commit() | |
finally: | |
conexion.close() | |
except (pymysql.err.OperationalError, pymysql.err.InternalError) as e: | |
print("Ocurrió un error al conectar: ", e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment