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;
- mysqli_real_escape_string
- 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?