What are the 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 and offers more advanced features and better performance. It also supports prepared statements, transactions, and stored procedures, which are not available in the original MySQL extension. It is recommended to use MySQLi over MySQL for new projects.

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

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

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