-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
47 lines (35 loc) · 1.17 KB
/
test.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
42
43
44
45
46
47
<?php
require 'init.php';
require 'BasicTableGateway.php';
require 'UserGateway.php';
/****** SETUP ******/
$sql = "create temporary table gw_users (
id int primary key auto_increment,
email varchar(255),
password varchar(255),
name varchar(255)
)";
$pdo->query($sql);
$data = [
'email' => '[email protected]',
'password' => password_hash('Curious Elk * 38', PASSWORD_DEFAULT),
'name' => 'Fooster',
];
/****** EXAMPLE BEGINS ******/
$userGW = new UserGateway($pdo);
$id = $userGW->create($data);
echo "Create: $id",PHP_EOL;
$user = $userGW->read($id);
echo "Read: ". json_encode($user),PHP_EOL;
$userGW->update(['name' => 'Wooster'], $id);
$user = $userGW->read($id);
echo "Update:".json_encode($user),PHP_EOL;
$users = $userGW->listBySql("SELECT * from gw_users");
echo "List: ". json_encode($users),PHP_EOL;
$user = $userGW->getByField("email", $data['email']);
echo "Find by column: ".json_encode($user),PHP_EOL;
$userGW->delete($id);
$user = $userGW->read($id);
echo "Delete: ".json_encode($user),PHP_EOL;
// attempt to use a non-existent column;
$user = $userGW->getByField("; drop table users", $data['email']);