I learned the following method to sanitize data
function sanitize($data)
{
return mysql_real_escape_string( $data);
}
Then the deprecation of some extension within mysql is becoming abit frustrating for beginners that did not know about it, however it is a learning experience to know PHP properly. It is recommended to use mysqli_real_escape_string instead and since this function requires 2 parameters, I have the following
function sanitize($data){
// 1. Create a database connection
$db = new mysqli('localhost','root','somepass','secured_login');
if($db->connect_errno){
$connect_error = 'Sorry, we are experiencing connection problems.';
die ($connect_error);
}
return htmlentities(strip_tags(mysqli_real_escape_string($db, $data)));
}
However, I have been getting the sense that many PHP programmers highly recommend using PDO method instead
My apology for such a long intro my question is... Is it safe to use the modified function sanitize where mysqli_real_escape_string is used instead mysql_real_escape_string?
if not!! then by using PDO I would need to learn OOP PHP instead of procedural. I hope I framed this question correctly. Is mixing both programming orientations (procedural and OOP) frowned upon.
What is the real advantage of using PDO in the longer? Thank you!