There is my database:
CREATE TABLE Persons (
ID int AUTO_INCREMENT,
Father varchar(255) NOT NULL,
Text varchar(255),
PRIMARY KEY (ID));
And there is my .txt file: (NULL, '1', 'text'),(NULL, '2', 'text'),(NULL, '3', 'text')...
Ok this works for me now:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$text_file = file_get_contents('newfile.txt');
$sql = "INSERT INTO `Persons` (`ID`, `Father`, `Text`) VALUES".$text_file;
// use exec() because no results are returned
$conn->exec($sql);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
And now how do i upload multiple txt files, like from multiple folders, or just one folder?