私は多くを検索したが、まだ答えを見つけることができなかったものをあなたの助けにしたいと思います。 質問のタイトルとして、私は列のデータ型を知らないmySqlデータベースにテーブルを作成しようとしています。基本的に、私はcsvファイルからデータベースに新しいテーブルを作成するためにPHPを使用します。最初の行には列名が含まれています。私は、csvファイルを選択して最初の行を使用してテーブルの列名を生成することができ、各列のデータ型を指定する必要がないphpMyAdminでこれを確認したので、これを行うことができることを知っています。mySql:わかりやすいデータ型のテーブルを作成するには?
$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();
}
こんにちは、それは間違いなく動作します。リンクありがとう。それは本当に助けになりました。私はそのリンクに基づいてソリューションを投稿します –