What are the advantages of using mysqli_ or PDO over the deprecated mysql_ functions in PHP for database operations?

The deprecated mysql_ functions in PHP are no longer recommended for database operations due to security vulnerabilities and lack of support in newer PHP versions. It is advised to use either mysqli_ or PDO for database operations as they offer more secure and flexible options for interacting with databases.

// Using mysqli_ for database operations
$mysqli = new mysqli("localhost", "username", "password", "database");

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

$query = $mysqli->query("SELECT * FROM table");

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

$mysqli->close();