I want the code to be executed only once, because everytime I refresh it, it returns to the sqlite database. Not run 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);
}
}