0
I want the code to run only once, because every time I refresh it re-enter the sqlite database. Without running from a button. code:
if(!file_exists($dir.$base)) {
$base_hndl = new SQLite3($dir.$base);
$requete = "CREATE TABLE 'contact' (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
nom TEXT NULL,
prenom TEXT NULL,
categorie TEXT NULL
)";
$result = $base_hndl->exec($requete);} else {
$row = 0;
$delemiter = ";" ;
$data = array();
if (($handle = fopen("contacts.csv", "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 2000, $delemiter)) !== FALSE)
{
$num = count($data);
$row++;
$base_hndl = new SQLite3($dir.$base);
$query_value = "";
$query = "INSERT INTO contact (nom,prenom,categorie) VALUES ( ";
for ($c = 0; $c < $num; $c++)
{
if($data[$c] == "")
{
$query_value .= "\"0\"";
}
else
{
//$query .= "'" . $data[$c] . "'";
$query_value .= "\"$data[$c]\"";
}
if ($c+1 < $num)
{
$query_value .= ",";
}
}
$query_value .= ")\n";
$result = $base_hndl->exec($query.$query_value);
}
fclose($handle);
}
}
You can create a table that only records the import day if that date already exists doesn’t matter. You can set the date field as
unique key
or no value of the date column can be repeated.– rray
Have you tried using session? so it only executes the code when it closes and opens the browser again
– Dexxtz
session_start();?
– akm
That can help you.
– Bruno Augusto