Files
Scripts_Python/mysql_fetch.py
2024-01-09 19:29:38 +01:00

30 lines
591 B
Python

import mysql.connector
#pip3 install mysql-connector-python
#pip install mysql
#pip install MySQL-python
#import MySQLdb
try:
conn = mysql.connector.connect(host="localhost",user="root",password="sncfp1p2", database="python")
cursor = conn.cursor()
name = "olivier"
id = 5
cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s""", (name, ))
rows = cursor.fetchall()
for row in rows:
print('{0} : {1} - {2}'.format(row[0], row[1], row[2]))
#conn.commit()
except Exception as e:
print("Erreur")
conn.rollback()
# raise e
finally:
conn.close()