What potential issues can arise from using the outdated mysql_ extension in PHP code?

Using the outdated mysql_ extension in PHP code can lead to security vulnerabilities, compatibility issues with newer versions of MySQL, and deprecated function warnings. To solve this issue, it is recommended to switch to the mysqli or PDO extension, which offer improved security features and support for prepared statements.

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

if ($mysqli->connect_error) {
    die('Connection failed: ' . $mysqli->connect_error);
}

// Perform a query using prepared statement
$stmt = $mysqli->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param('i', $userId);
$userId = 1;
$stmt->execute();
$result = $stmt->get_result();

while ($row = $result->fetch_assoc()) {
    // Process the data
}

$stmt->close();
$mysqli->close();