0

how can I get the column names without explicitly asking for it?

I have this SQL query.

SELECT * FROM Machines WHERE id='$id'

Is it possible to get the column names through a PHP function? Something like this:

mysqli_fetch_columns($result)

I understand that you can get the column names through a SQL Statement, however this is not practical for me. I would like to retreive the column names through some PHP function.

Lars Peterson
  • 1,508
  • 1
  • 10
  • 27

1 Answers1

3
include 'connection.php';

$result = $connection->query("select * from users");
while ($row = mysqli_fetch_field($result)) {
    $array[] = $row;
}

In $array you will get all column name

jack
  • 589
  • 8
  • 22