I'm making a script that reads a .txt file and put the data of each line in this file into a database. But the problem is that the file size is 7.5mb. and php won't allow this file size.
I also wrote that "ini_set('memory_limit','-1');" isn't recommended, so i'm wondering how to fix this.
My script:
$file = fopen("./ftp_imports/ingram/ingram_fees.txt", "r");
$first_row = fgets($file);
$column = explode(",", $first_row);
$columns = count($column);
while ($row = fgets($file)) {
$value = explode(",", $row);
$i = 0;
try {
// Add a SQL-query.
$i2 = 0;
$sql = "INSERT INTO ingram_fees (";
while ($i2 <= ($columns - 1)) {
if ($i2 < ($columns - 1)) {
$sql .= $column[$i2].",";
} else {
$sql .= $column[$i2];
}
$i++;
}
$sql .= ") VALUES (";
$i2 = 0;
while ($i2 <= ($columns - 1)) {
if ($i2 < ($columns - 1)) {
$sql .= ":".$column[$i2].",";
} else {
$sql .= ":".$column[$i2];
}
}
$sql .= ")";
$stmt = $db->prepare($sql);
$sql_array = array();
$i2 = 0;
while ($i2 <= ($columns - 1)) {
$key = ":".$column[$i2];
$sql_array[$key] = $value[$i];
}
$stmt->execute($sql_values);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
Maybe my code is a bit messy, thats because im a beginner in php :p
Can someone give me an example to fix this problem?
Thanks