How do I get the column names of a table into a PHP array using the mysqli extension? I need to fetch the column names of any given table without fetching any data from the
You can use array_keys() to get all the keys of an array,
$myarray = array('key1' => 'a', 'key2' => 'b')
$x = array_keys($myarray);
The result you want can be obtained from $x
$x = array(0 => 'key1', 1 => 'key2');
Inorder to get the column names of a table,
$sql = "SELECT * FROM table_name LIMIT 1";
$ref = $result->query($sql);
$row = mysqli_fetch_assoc($ref);
$x = array_keys($row);
now $x array contains the column names of the table