किसी php solutin की तलाश में है, तो:
पैकेज: https://github.com/uzi88/PHP_MySQL_wrapper
$db = new MySQL_wrapper(MySQL_HOST, MySQL_USER, MySQL_PASS, MySQL_DB);
$db->connect();
// this sample gets column names from first row of file
//$db->createTableFromCSV('test_files/countrylist.csv', 'csv_to_table_test');
// this sample generates column names
$db->createTableFromCSV('test_files/countrylist1.csv', 'csv_to_table_test_no_column_names', ',', '"', '\\', 0, array(), 'generate', '\r\n');
/** Create table from CSV file and imports CSV data to Table with possibility to update rows while import.
* @param string $file - CSV File path
* @param string $table - Table name
* @param string $delimiter - COLUMNS TERMINATED BY (Default: ',')
* @param string $enclosure - OPTIONALLY ENCLOSED BY (Default: '"')
* @param string $escape - ESCAPED BY (Default: '\')
* @param integer $ignore - Number of ignored rows (Default: 1)
* @param array $update - If row fields needed to be updated eg date format or increment (SQL format only @FIELD is variable with content of that field in CSV row) $update = array('SOME_DATE' => 'STR_TO_DATE(@SOME_DATE, "%d/%m/%Y")', 'SOME_INCREMENT' => '@SOME_INCREMENT + 1')
* @param string $getColumnsFrom - Get Columns Names from (file or generate) - this is important if there is update while inserting (Default: file)
* @param string $newLine - New line delimiter (Default: \n)
* @return number of inserted rows or false
*/
// function createTableFromCSV($file, $table, $delimiter = ',', $enclosure = '"', $escape = '\\', $ignore = 1, $update = array(), $getColumnsFrom = 'file', $newLine = '\r\n')
$db->close();
बिल्कुल सही नहीं है लेकिन आप लोड डेटा इन्फाइल http://dev.mysql.com/doc/refman/5.1/en/load-data.html का संदर्भ दे रहे हैं, पाठ फ़ाइल जिसके लिए एक CSV संरचित फ़ाइल जैसा दिखता है । – wisefish
उत्तर में मेरा अपडेट देखें –
आप CSV को CREATE TABLE (स्कीमा के साथ) में कनवर्ट करने के लिए इस टूल (https://csv-schema.surge.sh/) का उपयोग कर सकते हैं। यह फ़ील्ड प्रकार (काफी अच्छा) अनुमान लगाने का प्रयास करता है। – s1x