diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 |
commit | 7ef208fc1ae5a24d7b3cd2e22e969285fbf7262a (patch) | |
tree | 7995fdce15426408ea1f893c6842dc63cd2b2fae /model/User.php | |
parent | d0e23fd32cd2c968bdb905604c543b8c1bb8f6ee (diff) |
Add additional classes and functions
Diffstat (limited to 'model/User.php')
-rw-r--r-- | model/User.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/model/User.php b/model/User.php new file mode 100644 index 0000000..89a14a5 --- /dev/null +++ b/model/User.php @@ -0,0 +1,54 @@ +<?php + +class User { + public $id; + public $name = 'Unknown'; + public $date = 0; + + function get_by_name($name, $dbc) { + $sql = "SELECT user_id, user_date FROM users WHERE user_name = ?"; + $stmt = mysqli_stmt_init($dbc); + + if (!mysqli_stmt_prepare($stmt, $sql)) { + echo 'Failed to get user: ' . mysqli_error($dbc); + } + + mysqli_stmt_bind_param($stmt, "s", $name); + mysqli_stmt_execute($stmt); + + $result = mysqli_stmt_get_result($stmt); + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $this->id = $row['user_id']; + $this->name = $name; + $this->date = $row['user_date']; + } + } + + mysqli_free_result($result); + mysqli_stmt_close($stmt); + } + + function get_by_id($id, $dbc) { + $sql = "SELECT user_name, user_date FROM users WHERE user_id = " . mysqli_real_escape_string($dbc, $id); + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Failed to get user: ' . mysqli_error($dbc); + } + + if (mysqli_num_rows($result) == 0) { + } else { + while ($row = mysqli_fetch_assoc($result)) { + $this->id = $id; + $this->name = $row['user_name']; + $this->date = $row['user_date']; + } + } + + mysqli_free_result($result); + } + +}
\ No newline at end of file |