Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Last active May 15, 2020 00:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save harryWonder/56289db582b8123c5e5bb817353d3a5e to your computer and use it in GitHub Desktop.
This file extends the Db.php Class and provides two methods for creating a new user and fetching a new user.
<?php
require_once(__dir__ . '/Db.php');
class RegisterModel extends Db {
/**
* @param array
* @return array
* @desc Creates and returns a user record....
**/
public function createUser(array $user) :array
{
$this->query("INSERT INTO `db_user` (name, email, phone_no, password) VALUES (:name, :email, :phone_no, :password)");
$this->bind('name', $user['name']);
$this->bind('email', $user['email']);
$this->bind('phone_no', $user['phone']);
$this->bind('password', $user['password']);
if ($this->execute()) {
$Response = array(
'status' => true,
);
return $Response;
} else {
$Response = array(
'status' => false
);
return $Response;
}
}
/**
* @param string
* @return array
* @desc Returns a user record based on the method parameter....
**/
public function fetchUser(string $email) :array
{
$this->query("SELECT * FROM `db_user` WHERE `email` = :email");
$this->bind('email', $email);
$this->execute();
$User = $this->fetch();
if (!empty($User)) {
$Response = array(
'status' => true,
'data' => $User
);
return $Response;
}
return array(
'status' => false,
'data' => []
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment