0

I need some suggestions to prevent SQL injections. I've a mysqli query to fetch some names from database.

$con = mysqli_connect( "localhost","my_user","my_password","my_db" );

mysqli_query( $con, "SELECT names FROM my_table WHERE names LIKE '$names' AND DATE_FORMAT(DOB, '%d/%m/%Y') = '$date'" );

I want to prevent my query from SQL injection. I read some articles regarding SQL injections and saw that the following methods can be used to prevent SQL injection;

  1. mysqli_real_escape_string
  2. Prepared Statements

But I am confused that which method is more secure. Or any other method is available which is more secure than above methods?

How can I implement this with my sample query?

user229044
  • 232,980
  • 40
  • 330
  • 338
Arun Chandran
  • 310
  • 5
  • 24

0 Answers0