In PHP, what are the advantages of using a database class or the MySQLi extension over the outdated MySQL extension?

Using a database class or the MySQLi extension in PHP is advantageous over the outdated MySQL extension because they offer improved security features, support for prepared statements which helps prevent SQL injection attacks, and better overall performance. Additionally, MySQLi provides object-oriented interface which makes it easier to work with databases in PHP.

// Using MySQLi extension to connect to a database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";