What are the benefits of using mysqli over mysql_* in PHP?

Using mysqli over mysql_* in PHP is beneficial because mysqli offers improved security features, support for prepared statements, and object-oriented interface. Prepared statements help prevent SQL injection attacks by separating SQL logic from user input. Additionally, mysqli is actively maintained and supported by PHP, while mysql_* functions are deprecated and no longer recommended for use.

// Connect to MySQL using mysqli
$servername = "localhost";
$username = "username";
$password = "password";
$database = "dbname";

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

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