What are common errors that can lead to a bool(false) result when executing a SELECT query in PHP?

One common error that can lead to a bool(false) result when executing a SELECT query in PHP is incorrect SQL syntax. Make sure the SQL query is properly formatted and all table and column names are correct. Another issue could be a connection problem to the database, so ensure that the database connection is established correctly before executing the query. Lastly, check for any errors in the query execution process that could be causing the bool(false) result.

// Example of a correct way to execute a SELECT query in PHP
$conn = new mysqli($servername, $username, $password, $dbname);

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

$sql = "SELECT * FROM table_name";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();