I am trying to use this code to import a csv
file into my MySQL database:
... Thanks for solved that question!! ....
What am I doing wrong?
Guys I could solved that problem but now... I have an other problem, this is the code now:
<?php
$databasehost = "localhost";
$databasename = "cauctti";
$databasetable = "sample";
$databaseusername="root";
$databasepassword = "toor";
$fieldseparator = ";";
$lineseparator = "\r|n";
$csvfile = "Reporting.csv";
if(!file_exists($csvfile)) {
die("File not found. Make sure you specified the correct path.");
}
try {
$pdo = new PDO("mysql:host=$databasehost;dbname=$databasename",
$databaseusername, $databasepassword,
array(
PDO::MYSQL_ATTR_LOCAL_INFILE => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
)
);
} catch (PDOException $e) {
die("database connection failed: ".$e->getMessage());
}
$affectedRows = $pdo->exec("
LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." INTO TABLE `$databasetable`
FIELDS TERMINATED BY ".$pdo->quote($fieldseparator)."
LINES TERMINATED BY ".$pdo->quote($lineseparator));
echo "Loaded a total of $affectedRows records from this csv file.\n";
?>
When I try to run it, only insert one row on the table...
Loaded a total of 1 records from this csv file.
Why it only gets one row when my csv file have like 5.000 entries...