What is the best way to increment a database value in PHP without using two separate database commands?

When trying to increment a database value in PHP without using two separate database commands, you can achieve this by using a single SQL query that updates the value directly in the database. This can be done by using the SQL `UPDATE` statement with the `SET` clause to increment the value by a specified amount.

<?php

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

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

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

// Increment the value in the database
$sql = "UPDATE table_name SET column_name = column_name + 1 WHERE condition";

if ($conn->query($sql) === TRUE) {
    echo "Value successfully incremented";
} else {
    echo "Error updating record: " . $conn->error;
}

// Close the connection
$conn->close();

?>