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

35
mysql_fetch_2.py Normal file
View File

@@ -0,0 +1,35 @@
import pymysql
# pip3 install PyMySQL
# http://zetcode.com/python/pymysql/
con = pymysql.connect('localhost', 'root', 'sncfp1p2', 'python')
with con:
cursor = con.cursor()
cursor.execute("SELECT VERSION()")
version = cursor.fetchone()
print("Database version: {}".format(version[0]))
name = "bruno"
age = 50
# cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s""", (name, ))
cursor.execute("""SELECT id, name, age FROM visiteurs WHERE name = %s AND age = %s""", (name,age))
rows = cursor.fetchall()
for row in rows:
print('{0} : {1} - {2}'.format(row[0], row[1], row[2]))
print("The query affected {} rows".format(cursor.rowcount))
#age = 35
# cursor.execute("""SELECT id, name, age FROM visiteurs WHERE age < %s""", (age))
cursor.execute("""SELECT id, name, age FROM visiteurs ORDER BY age LIMIT 1""")
jeune = cursor.fetchone()
print("Le + jeune : {0} - {1} - {2}".format(jeune[0], jeune[1], jeune[2]))
print("The query affected {} rows".format(cursor.rowcount))