What steps can be taken to optimize performance when fetching all columns using SELECT * in a MySQL query for PHP array creation?

Fetching all columns using SELECT * in a MySQL query can lead to performance issues, especially when creating PHP arrays. To optimize performance, it is recommended to explicitly list the columns you need in the SELECT statement instead of using SELECT *. This reduces the amount of data being retrieved from the database and can improve query performance.

// Explicitly list the columns you need in the SELECT statement
$query = "SELECT column1, column2, column3 FROM table_name";
$result = mysqli_query($connection, $query);

$data = array();
while ($row = mysqli_fetch_assoc($result)) {
    $data[] = $row;
}

// Now $data array will only contain the specified columns, optimizing performance