Advertisement
jcarlosriverae

ejemplo conexion BD python

Nov 12th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. def conexionBDAlquimia():
  2.     try:
  3.         conn = mariadb.connect(
  4.             user="xxxxx",
  5.             password="xxxxx",
  6.             host="alquimia-produccion.czyvqwotxq1n.us-east-1.rds.amazonaws.com",
  7.             port=3306,
  8.             database="alquimia_vitae"
  9.         )
  10.     except mariadb.Error as e:
  11.         print(f"Error en conexiΓ³n a base de datos: {e}")
  12.         sys.exit(1)
  13.     cur = conn.cursor()
  14.     return cur
  15.  
  16. def consultaSaldoCuentaAlquimia(cur,idCuenta):
  17.     try:
  18.         cur.execute(
  19.             "select saldo_ahorro from alquimia_vitae.cuenta_ahorro_cliente where id_cuenta_ahorro ="+str(idCuenta)
  20.             )
  21.         record = cur.fetchone()        
  22.         saldo = record[0]
  23.         return saldo
  24.            
  25.     except mariadb.ProgrammingError as e:
  26.         print(f"Error en consulta a base de datos: {e}")
  27.         #sys.exit(1)
  28.  
  29. def determinaCuentaAlquimiaPorCLABE(cur,clabe):
  30.     try:
  31.         cur.execute(
  32.             "select id_cuenta_ahorro from cuenta_ahorro_medio_pago where no_cuenta_medio_pago ='"+str(clabe)+"'"
  33.             )
  34.         record = cur.fetchone()
  35.         idCuenta = record[0]
  36.         return idCuenta            
  37.     except mariadb.ProgrammingError as e:
  38.         print(f"Error en consulta a base de datos: {e}")
  39.         #sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement