Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 2, 2019 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ae85d0b5e004e9c8c9176a91959a213f to your computer and use it in GitHub Desktop.
Save parzibyte/ae85d0b5e004e9c8c9176a91959a213f to your computer and use it in GitHub Desktop.
import pymysql
try:
conexion = pymysql.connect(host='localhost',
user='root',
password='',
db='peliculas')
try:
with conexion.cursor() as cursor:
consulta = "SELECT id, titulo, anio FROM peliculas WHERE anio > %s;"
cursor.execute(consulta, (2000))
# Con fetchall traemos todas las filas
peliculas = cursor.fetchall()
# Recorrer e imprimir
for pelicula in peliculas:
print(pelicula)
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