-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadOne.py
More file actions
26 lines (24 loc) · 795 Bytes
/
Copy pathreadOne.py
File metadata and controls
26 lines (24 loc) · 795 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
26
import mysql.connector
from mysql.connector import Error
conexion=None
try:
# nos conectamos con la BD
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() # creando el cursor
cursor.execute("select *from persona where id=1")
resultado=cursor.fetchone()
print(resultado)
except Error as ex:
print("Ha ocurrido un error:",ex)
finally:
print("Cerrando la conexión....")
if conexion.is_connected():
conexion.close()
print("Conexión cerrada")