connect_error) { die("Connection failed: " . $conn->connect_error); } // $fn = fopen("myfile.txt", "r"); // $result = fgets($fn); // echo $result; // fclose($fn); $handle = fopen($dataFileName, "r"); if ($handle) { $text=""; $counter = 0; while (($line = fgets($handle)) !== false) { // process the line read. if (substr($line, 0, 1) === '[') { //Remove the first '[' $line = substr($line, 1); } if (substr($line, -1, 1) === ']') { //Remove the last ']' $line = substr($line, 0, -1); } if (substr($line, -3, 1) === ',') { //Remove the ',\n' $line = substr($line, 0, -3); } //insert record in database $sql = "INSERT INTO " . $tableName . " (data, test_name) VALUES ('".$line."', 'TEST_1')"; if ($conn->query($sql) === TRUE) { $text = $text."Line ".$counter."added\n"; } else { $text = $text . "Line " . $counter . "NOT added\n"; } $counter++; } fclose($handle); echo $text; } else { echo "Error opening file"; } // if ($conn->query($sql) === TRUE) { // echo "New record created successfully"; // } else { // echo "Error: " . $sql . "
" . $conn->error; // } $conn->close();