What are the potential risks of using outdated MySQL functions like mysql_connect and mysql_query in PHP?

Using outdated MySQL functions like mysql_connect and mysql_query in PHP can pose security risks as they are deprecated and no longer supported in newer versions of PHP. This can leave your application vulnerable to SQL injection attacks and other security threats. It is recommended to switch to using MySQLi or PDO extensions for database connectivity and prepared statements to prevent these risks.

// Connect to MySQL using MySQLi
$mysqli = new mysqli("localhost", "username", "password", "database");

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

// Perform a query using prepared statement
$stmt = $mysqli->prepare("SELECT * FROM table_name WHERE column_name = ?");
$stmt->bind_param("s", $value);
$value = "example";
$stmt->execute();
$result = $stmt->get_result();

// Fetch results
while ($row = $result->fetch_assoc()) {
    // Do something with the data
}

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