Why is it recommended to use mysqli instead of mysql functions in PHP for database queries?

It is recommended to use mysqli instead of mysql functions in PHP for database queries because mysqli offers improved security features, support for prepared statements, and better performance compared to the older mysql functions. Mysqli is also actively maintained and supported by the PHP community, making it a more reliable choice for interacting with databases.

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

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

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