What are the differences between using mysqli_query and the older mysql_query in PHP for database operations?

The main difference between using mysqli_query and mysql_query in PHP for database operations is that mysqli_query is the improved and more secure version of mysql_query. mysqli_query supports prepared statements which help prevent SQL injection attacks, while mysql_query does not. It is recommended to use mysqli_query for database operations as mysql_query has been deprecated in PHP.

// Using mysqli_query for database operations
$connection = mysqli_connect("localhost", "username", "password", "database");

$query = "SELECT * FROM table_name";
$result = mysqli_query($connection, $query);

// Fetch data from the result set
while ($row = mysqli_fetch_assoc($result)) {
    echo $row['column_name'] . "<br>";
}

// Close the connection
mysqli_close($connection);