What is the difference between mysql_fetch_object and mysqli_fetch_object in PHP?

The main difference between mysql_fetch_object and mysqli_fetch_object in PHP is that mysql_fetch_object is part of the deprecated MySQL extension, while mysqli_fetch_object is part of the improved MySQLi extension. It is recommended to use mysqli_fetch_object as it provides better security, performance, and features compared to the older mysql_fetch_object function.

// Using mysqli_fetch_object to fetch data from a MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

if ($result = $mysqli->query("SELECT * FROM table")) {
    while ($row = $result->fetch_object()) {
        // Do something with $row
    }
    $result->close();
}

$mysqli->close();