よく検索しましたが、まだ答えが見つかりませんでした。質問のタイトルにあるように、mySqlデータベースに列のデータ型がわからないテーブルを作成しようとしています。基本的に、私はphpを使用して、csvファイルからデータベースに新しいテーブルを作成します。最初の行には列名が含まれています。phpMyAdminでcsvファイルを選択し、最初の行を使用してテーブルの列名を生成でき、各列のデータ型を指定する必要がないため、これを実行できることを知っています。
これまでのところ、これは私のphpコードです:
$databaseName="myDatabase";
mysql_connect("localhost","xxxxxx","xxxxxxxx");
mysql_select_db($databaseName);
for($i = 0; $i < count($newFiles); $i++){//traverse the table that contains the file names
$content = file($newFileLocation.$newFiles[$i]);
//First line: $content[0];
$firstLine=$content[0];//save first line which are the column names
//echo $firstLine;
$tableName= str_replace('.txt','', $newFiles[$i]);//remove the .txt to use for table name
//echo $tableName."\n";
echo "\n\ncreating tables\n\n";
/*mysql_query("load data local infile '$newFiles[$i]'
into table $tableName
fields terminated by ','
lines terminated by '\n'
($firstLine) "); */
mysql_close();
}