Lars Peterson Lars Peterson - 2 years ago 63
SQL Question

Get Column Names with SQL Query

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:


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.

Answer Source
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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download