Advertisement
NubeColectiva

Script Para Insertar Datos en MySQL

Dec 3rd, 2023
1,075
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | Source Code | 0 0
  1. import mysql.connector
  2.  
  3. mydb = mysql.connector.connect(
  4.   host="localhost",
  5.   user="root",
  6.   password="",
  7.   database="test"
  8. )
  9.  
  10. mycursor = mydb.cursor()
  11.  
  12. sql = "INSERT INTO empleados (dni, nombre, direccion, area, descripcion) VALUES (%s, %s, %s, %s, %s)"
  13. val = ("12345678", "Pedro Torres", "Av. Eclipse # 456", "rrhh", "Profesional en Recursos Humanos")
  14. mycursor.execute(sql, val)
  15. mydb.commit()
  16. print(mycursor.rowcount, "registro insertado !")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement