Prevent SQL Injection

Total Post:113

Points:791
Python 
 137  View(s)
Ratings:
Rate this:

What is Prevent SQL Injection in Python ?


  1. Post:140

    Points:984
    Re: Prevent SQL Injection

    Prevent SQL Injection :

    prevent SQL injections, which is a common web hacking technique to destroy your database import mysql.connector .

    mydb = mysql.connector.connect(
    
      host="localhost",
      user="yourusername",
      passwd="yourpassword",
      database="mydatabase"
    )
    mycursor = mydb.cursor()
    sql = "UPDATE customers SET address = %s WHERE address = %s"
    val = ("Valley 345", "Canyon 123")
    mycursor.execute(sql, val)
    mydb.commit()
    print(mycursor.rowcount, "record(s) affected")

    Python MySQL Join :

    users: 

    { id: 1, name: 'rohan', fav: 154}, 
    { id: 2, name: 'prakash', fav: 154},
    { id: 3, name: 'Arti', fav: 155},
    { id: 4, name: 'Aditya', fav:},
    { id: 5, name: 'Vishal', fav:}


    Products :

    { id: 154, name: 'Chocolate Heaven' }, 
    { id: 155, name: 'Tasty Lemons' },
    { id: 156, name: 'Vanilla Dreams' }
    mycursor = mydb.cursor() 
    sql = "SELECT \ 
      users.name AS user, \
      products.name AS favorite \
      FROM users \
      INNER JOIN products ON users.fav = products.id"
    mycursor.execute(sql)
    myresult = mycursor.fetchall()
    for x in myresult:
      print(x)

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!