-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.php
More file actions
68 lines (54 loc) · 1.53 KB
/
sql.php
File metadata and controls
68 lines (54 loc) · 1.53 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
$executionStartTime = microtime(true);
$dsn = "sqlite:db/viewer.sq3";
$options = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new \PDO($dsn);
// Set errormode to exceptions
$pdo->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
);
} catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int) $e->getCode());
}
$pdo->exec("CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY,
title TEXT,
message TEXT,
time INTEGER)");
$pdo->beginTransaction();
$start = 1;
$end = $start + 100;
for ($id = $start; $id <= $end; $id++) {
insertTest($id, 'hi world');
}
$pdo->commit();
function insertTest($id, $title)
{
global $pdo;
// echo $title;
// var_dump($title);
$msgTable = "messages";
$sql = "INSERT INTO {$msgTable}
(title, message, time)
VALUES (:title, :message, :times)";
$data = [
'title' => $title,
'message' => 'msg',
'times' => 10
];
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
$lastInsertId = $pdo->lastInsertId();
//echo 'lastInsertId= ' . $lastInsertId;
//var_dump($lastInsertId);
return $lastInsertId;
}
$executionEndTime = microtime(true);
$seconds = $executionEndTime - $executionStartTime;
error_log(PHP_EOL . "This script took $seconds to execute.");