What are the main differences between MySQL and MySQLi in PHP?

MySQL and MySQLi are both PHP extensions used to interact with MySQL databases. MySQLi (MySQL Improved) is an improved version of the original MySQL extension, providing a more secure and feature-rich way to work with MySQL databases. Some key differences include support for prepared statements, object-oriented interface, support for transactions, and enhanced debugging capabilities.

// Example of connecting to a MySQL database using MySQLi
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";

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

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