What are the differences between using the mysql extension and the mysqli extension in PHP for database operations?

The main difference between using the mysql extension and the mysqli extension in PHP for database operations is that the mysql extension is deprecated as of PHP 5.5.0 and removed in PHP 7.0.0, while the mysqli extension is the improved version that supports MySQL databases. It is recommended to use the mysqli extension for better security, performance, and functionality.

// Using mysqli extension for database operations
$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";
$conn->close();