Hi, I would appreciate it if someone could help me with this problem. I want to print each of the results that this query would throw at me, as when it is executed in MySQL. What I want is for example to obtain all the records that contain the word "source" in the "Product" column, several products have it in the table and I would like to print all the results.
import MySQLdb
def consultar(Producto):
try:
db = MySQLdb.connect("localhost","root","1234","pcsolution")
cursor = db.cursor()
sql = ("SELECT * FROM productos WHERE Producto LIKE ='"+Producto+"';")
cursor.execute(sql)
for (Codigo,Producto,Unidades) in cursor:
return Producto,Marca,Unidades
db.commit()
db.close()
except:
return ("Problemas de conexión")
Producto,Marca,Unidades = consultar("fuente")
print (Producto)
print (Marca)
print (Unidades)