-
Notifications
You must be signed in to change notification settings - Fork 4
/
mysql.php
41 lines (31 loc) · 1.06 KB
/
mysql.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
39
40
41
<?php
// mysql 5.8
$start = time();
$pdo = new PDO("mysql:host=localhost;dbname=testdb", 'login', 'password');
$pdo->exec('SET GLOBAL tmp_table_size = 1024 * 1024 * 1024 * 2; SET GLOBAL max_heap_table_size = 1024 * 1024 * 1024 * 2;');
$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='MEMORY';");
$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']})";
}
$r = $pdo->exec($sql);
if (!$r) {
var_export($pdo->errorInfo());
}
echo "$i\n";
$i++;
}
unset($visitsData);
echo 'init time: ' . (time() - $start) . ', memory: ' . intval(memory_get_usage() / 1000000) . "\n";