Exporting SQL data to CSV using PHP [closed]

I am trying to export sql tables to CSV, however, my output doesn’t produce column headings. How can I retrieve the column headings from SQL table without manually creating an array?

I tried mysqli_num_fields but it is not working.
I get an error code saying that it doesn’t convert string. I am not sure what else to use.
Fatal error: Uncaught Error: Call to undefined function mysql_num_fields() in C:xampphtdocsnew.php:16 Here is the error that I am receiving.
I want to export tables to excel with dynamic column headings