Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getById($id)
- {
- $res = $this->conn->query("SELECT * FROM {$this->tbl} WHERE id = $id");
- if ($res->num_rows > 0) {
- $user = $res->fetch_assoc();
- return $user;
- }
- return false;
- }
- public function update($data)
- {
- $user = $this->getById($data['user_id']);
- if ($user['username'] == $data['username']) {
- $username = $data['username'];
- $data['username'] = false;
- } else {
- $username = $data['username'];
- }
- if ($data['password'] == null) {
- $password = $data['password2'];
- $data['password'] = false;
- } else {
- $password = md5($data['password']);
- }
- $validasi = $this->_validasi($data);
- if ($validasi == []) {
- $res = $this->conn->query("UPDATE {$this->tbl} SET nama='{$data['nama']}',username='{$username}',password='{$password}',email='{$data['email']}' WHERE id={$data['user_id']}");
- $this->conn->close();
- return $res;
- } else {
- return $validasi;
- }
- }
- public function delete($id)
- {
- $this->conn->query("DELETE FROM {$this->tbl} WHERE id = {$id}");
- if ($this->conn->affected_rows == 1) {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement