What are the consequences of using outdated PHP functions like mysql_real_escape_string in terms of security vulnerabilities and best practices?

Using outdated PHP functions like mysql_real_escape_string can lead to security vulnerabilities such as SQL injection attacks. It is recommended to use parameterized queries or prepared statements to properly sanitize input data and prevent these vulnerabilities.

// Using parameterized queries to prevent SQL injection
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Prepare a SQL statement
$stmt = $mysqli->prepare("INSERT INTO table_name (column1, column2) VALUES (?, ?)");

// Bind parameters
$stmt->bind_param("ss", $value1, $value2);

// Set parameter values
$value1 = "value1";
$value2 = "value2";

// Execute the statement
$stmt->execute();

// Close the statement and connection
$stmt->close();
$mysqli->close();