-
Notifications
You must be signed in to change notification settings - Fork 4
/
sqlite.php
36 lines (26 loc) · 941 Bytes
/
sqlite.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
// sqlite 3.7.17
$start = time();
$pdo = new PDO("sqlite::memory:");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("CREATE TABLE visits (
id int NOT NULL PRIMARY KEY,
user int NOT NULL,
location int NOT NULL,
visited_at int NOT NULL,
mark tinyint NOT NULL
)");
$i = 1;
while ($visitsData = @file_get_contents("data/visits_$i.json")) {
$visitsData = json_decode($visitsData, true);
foreach ($visitsData['visits'] as $k => $row) {
$sql = "INSERT INTO visits (id, user, location, visited_at, mark) VALUES ({$row['id']}, {$row['user']}, {$row['location']}, {$row['visited_at']}, {$row['mark']})";
$pdo->exec($sql);
}
echo "$i\n";
$i++;
}
unset($visitsData);
echo 'init time: ' . (time() - $start) . ', memory: ' . intval(memory_get_usage() / 1000000) . "\n";
//$count = $pdo->query("SELECT count(*) FROM visits")->fetch(); var_export($count);
sleep(3600);