-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.py
More file actions
25 lines (23 loc) · 804 Bytes
/
Copy pathinsert.py
File metadata and controls
25 lines (23 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import mysql.connector
from mysql.connector import Error
conexion=None
try:
conexion=mysql.connector.connect(
host='localhost', # hosting
port=3306, # puerto mysql
user='root', # nombre del usuario
password='', # contraseña del usuario
db='pooc2iei' # nombre de la base de datos
)
if conexion.is_connected():
cursor=conexion.cursor()
query="INSERT INTO persona (id,apellidos,nombres,edad) VALUES (0,'Sandoval','Diego',19)"
cursor.execute(query)
conexion.commit()
print("Registro agregado correctamente...")
except Error as ex:
print("Error de conexión:",ex)
finally:
if conexion.is_connected():
conexion.close()
print("La conexión ha sido cerrada")