Skip to content

Instantly share code, notes, and snippets.

@terremoth
Created January 5, 2022 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terremoth/fdd6044b9dca1041ed51f9c3d4ae2189 to your computer and use it in GitHub Desktop.
Save terremoth/fdd6044b9dca1041ed51f9c3d4ae2189 to your computer and use it in GitHub Desktop.
After download the Sendgrid email activity exported data, create a SQLite to save some data
<?php
$db = new PDO('sqlite:csvdata.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($file = fopen("parsed.csv", "r")) {
while(!feof($file)) {
$line = fgets($file);
$parts = explode(",", $line);
$status = $parts[0];
$subject = $parts[1];
$from = $parts[2];
$email = $parts[3];
$sql = 'INSERT INTO csv (`status`, `subject`, `from`, `email`) VALUES (?,?,?,?)';
$stmt = $db->prepare($sql);
$result = $stmt->execute([$status , $subject, $from, $email]);
}
fclose($file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment