What are some best practices for naming variables and columns when working with mysqli in PHP?

When working with mysqli in PHP, it is important to follow best practices for naming variables and columns to ensure clarity and maintainability of the code. Variable and column names should be descriptive, concise, and follow a consistent naming convention such as camelCase or snake_case. Avoid using reserved words or special characters in names to prevent conflicts or errors.

// Example of naming variables and columns in mysqli
$servername = "localhost";
$username = "root";
$password = "";
$database = "myDB";

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

// Example of querying a database with named columns
$sql = "SELECT id, first_name, last_name FROM users";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "ID: " . $row["id"]. " - Name: " . $row["first_name"]. " " . $row["last_name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();