-
Notifications
You must be signed in to change notification settings - Fork 4
/
memsql.php
38 lines (28 loc) · 943 Bytes
/
memsql.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
37
38
<?php
// memsql 6.8.8
// https://en.wikipedia.org/wiki/MemSQL
$start = time();
$pdo = new PDO("mysql:host=127.0.0.1;dbname=testdb", 'login', 'password');
$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
) ENGINE='MemSQL';");
$i = 1;
while ($visitsData = @file_get_contents("data/visits_$i.json")) {
$visitsData = json_decode($visitsData, true);
$sql = "INSERT INTO visits (id, user, location, visited_at, mark) VALUES ";
foreach ($visitsData['visits'] as $k => $row) {
if ($k) {
$sql .= ',';
}
$sql .= "({$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";