What are the potential pitfalls of using SELECT * in a database query when fetching data for display in PHP?
Using SELECT * in a database query can potentially fetch more data than needed, leading to increased load on the database server and slower query performance. It can also expose sensitive information if new columns are added to the table in the future. To avoid these pitfalls, it's best to explicitly specify the columns to fetch in the SELECT statement.
// Specify the columns to fetch instead of using SELECT *
$query = "SELECT column1, column2, column3 FROM table_name";
$result = mysqli_query($connection, $query);
// Fetch and display the data
while ($row = mysqli_fetch_assoc($result)) {
echo $row['column1'] . " - " . $row['column2'] . " - " . $row['column3'] . "<br>";
}