1st commit

This commit is contained in:
2024-01-09 19:29:38 +01:00
commit 6882eb00aa
15 changed files with 584 additions and 0 deletions

30
mysql_fetch.py Normal file
View File

@@ -0,0 +1,30 @@
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()