Skip to main content
1 of 2
CS GO
  • 111
  • 3

Is this code perfect to stop sql injection in python?

I'm new to python and i am learning Database connection from here

This is the code i am using to insert data:

conn = mysql.connector.connect(user="user", password="password", host="127.0.0.1", database="db")
cursor = conn.cursor()
query = ("INSERT INTO test(name,email) VALUES(%s,%s)")
data = ("cool", "cool")
cursor.execute(query, data)
conn.commit()
cursor.close()
conn.close()

This type of data insertion is safe and can stop sql injection ?

CS GO
  • 111
  • 3