-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
35 lines (28 loc) · 903 Bytes
/
index.php
File metadata and controls
35 lines (28 loc) · 903 Bytes
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
<?php
$dsn = "mysql:host=db;dbname=docker_compose_pet_project;charset=utf8";
try{
$conn = new \PDO($dsn, "dcpp", "dcpp");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
var_dump($e->getMessage());
}
$stmt = $conn->query("SELECT * FROM users");
$tpl = <<<EOT
<h3>{id}</h3>
<p>customer id: <b>{customer_id}</b><br />
age: <b>{age}</b><br />
city: <b>{city}</b><br />
email: <b>{email}</b><br />
firstname: <b>{firstname}</b><br />
lastname: <b>{lastname}</b></p>
EOT;
foreach ($stmt->fetchAll() as $k => $item) {
echo preg_replace_callback("/{([^}]+)}/", function ($matches) use ($item)
{
if ($matches[1] == 'id') {
return bin2hex($item[$matches[1]]);
}
return $item[$matches[1]];
}, $tpl);
}