No Description

sqlgen1.py 922B

123456789101112131415161718192021222324252627282930313233343536
  1. import mysql.connector
  2. from random import randint
  3. try:
  4. db = mysql.connector.connect(host="localhost", user="root", passwd="python1234", db="sqlinjection")
  5. cursor = db.cursor()
  6. delTable = "DROP TABLE IF EXISTS phonebook;"
  7. cursor.execute(delTable)
  8. creTable = "CREATE TABLE phonebook (name VARCHAR(20) NOT NULL, phone VARCHAR(12) NOT NULL);"
  9. cursor.execute(creTable)
  10. entries = ["Alan", "Ada", "Donald", "Grace", "Claude", "Ken", "Dennis", "Tim", "Tony", "Vint"]
  11. for i in range(len(entries)):
  12. randphone = str(randint(100, 999)) + "-" + str(randint(100, 999)) + "-" + str(randint(1000, 9999))
  13. insDB = "insert into phonebook (name, phone) VALUES ('"
  14. insDB += entries[i]
  15. insDB += "' , '"
  16. insDB += randphone
  17. insDB += "');"
  18. cursor.execute(insDB)
  19. db.commit()
  20. cursor.close()
  21. db.close()
  22. except Exception as e:
  23. print e