$handle = fopen("test.csv", "r");
// Read first (headers) record only)
$data = fgetcsv($handle, 1000, ",");
$sql= 'CREATE TABLE table_name (';
for($i=0;$i<count($data); $i++)
{
$sql .= $data[$i].' VARCHAR(50), ';
}
//The line below gets rid of the comma
$sql = substr($sql,0,strlen($sql)-2);
$sql .= ')';
echo $sql;
fclose($handle);
Reference: https://bytes.com/topic/mysql/answers/746696-create-mysql-table-field-headings-line-csv-file
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.