forked from MagnoEfren/tkinter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconexion.py
More file actions
48 lines (36 loc) · 1.59 KB
/
conexion.py
File metadata and controls
48 lines (36 loc) · 1.59 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Registro de datos en MySQL desde una GUI en TkInter
# @autor: Magno Efren
# Youtube: https://www.youtube.com/c/MagnoEfren
import mysql.connector #pip install mysql-connector-python
class Registro_datos():
def __init__(self):
self.conexion = mysql.connector.connect( host='localhost',
database ='base_datos',
user = 'root',
password ='admin')
def inserta_producto(self,codigo, nombre, modelo, precio, cantidad):
cur = self.conexion.cursor()
sql='''INSERT INTO productos (CODIGO, NOMBRE, MODELO, PRECIO, CANTIDAD)
VALUES('{}', '{}','{}', '{}','{}')'''.format(codigo, nombre, modelo, precio, cantidad)
cur.execute(sql)
self.conexion.commit()
cur.close()
def mostrar_productos(self):
cursor = self.conexion.cursor()
sql = "SELECT * FROM productos "
cursor.execute(sql)
registro = cursor.fetchall()
return registro
def busca_producto(self, nombre_producto):
cur = self.conexion.cursor()
sql = "SELECT * FROM productos WHERE NOMBRE = {}".format(nombre_producto)
cur.execute(sql)
nombreX = cur.fetchall()
cur.close()
return nombreX
def elimina_productos(self,nombre):
cur = self.conexion.cursor()
sql='''DELETE FROM productos WHERE NOMBRE = {}'''.format(nombre)
cur.execute(sql)
self.conexion.commit()
cur.close()