forked from d35h/Email-pr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate-table.php
More file actions
51 lines (46 loc) · 1.28 KB
/
Create-table.php
File metadata and controls
51 lines (46 loc) · 1.28 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
<?php
//////////////////////// Functions ////////////////////////
function PDOConnect($host, $database, $user, $password) {
$dns = 'mysqli:dbname='.$database.";host=".$host;
$pdo = new \PDO($dns, $user, $password, [
\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
\PDO::ATTR_PERSISTENT => TRUE,
]);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $pdo;
}
////////////////////////////////////////////////////////////
$pdo = PDOConnect('localhost', 'cl_db', 'root', 'mescalito1');
//array for storage result
$rows = [];
$statement = $pdo->prepare('SELECT * FROM `data`');
$statement->execute();
foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $row) {
array_push($rows, $row);
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<table class="values-table">
<th>
<td class="td-mid">field1</td>
<td class="td-mid">field2</td>
</th>
<?php if (count($rows)):?>
<?php foreach ($rows as $row):?>
<tr>
<td class="value"><?php echo $row['field1']?></td>
<td class="value"><?php echo $row['field2']?></td>
</tr>
<?php endforeach?>
<?php else:?>
<tr>
<td class="value" colspan="2">No records found</td>
</tr>
<?php endif?>
</table>
</body>
</html>