What are the potential security risks of using outdated PHP functions like mysql_connect?

Using outdated PHP functions like mysql_connect can pose security risks as they may contain vulnerabilities that can be exploited by attackers. It is recommended to use modern and secure alternatives like PDO or MySQLi for database connections to ensure better security and protection against potential attacks.

// Using PDO for secure database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}