Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Content-type: text/html; charset=UTF-8");
- include_once $_SERVER['DOCUMENT_ROOT']."/MI/Model/Beans/User.php";
- //include ("../Beans/User.php");
- include_once 'DAO.php';
- class DAO_User extends DAO {
- /* *****************************************************
- * constructor method
- ******************************************************/
- public function __construct () {
- parent::__construct();
- }
- /* *****************************************************
- * interfaces methods
- ******************************************************/
- public function create($obj){
- $this->connection = Database::getInstance()->OpenConnection();
- $object_class = get_class($obj);
- $sql = "INSERT INTO ".$object_class."(name, user_name, password, email, idAdministrator) VALUES (?, ?, ?, ?, ?);";
- $statement = $this->connection->prepare($sql);
- if (!$statement) {
- echo 'erro na consulta: '. $this->connection->errno .' - '. $this->connection->error;
- }
- $statement->bind_param(ssssi,$obj->getName(), $obj->getUser_Name(), $obj->getPassword, $obj->getEmail, $obj->getIdAdministrator);
- $statement->execute();
- $statement->close();
- $this->connection->close();
- }
- public function read() {
- return null;
- }
- public function readById($id) { return null; }
- public function update($obj) { return null; }
- public function delete($obj) { return null; }
- /* *****************************************************
- * specific methods
- ******************************************************/
- public function login($userName, $password){
- $this->connection = Database::getInstance()->OpenConnection();
- $sql = "select * from user where user_name = ? and password = ?;";
- $statement = mysqli_prepare($this->connection, $sql);
- //if any error happen in connection
- if (!$statement) {
- echo 'erro na consulta: '. $this->connection->errno .' - '. $this->connection->error;
- }
- //associate the user name and password with sql parameters,
- //execute the query and store the result
- $statement->bind_param('ss', $userName,$password);
- $statement->execute();
- $result = $statement->get_result();
- $user;
- //create and set the user variable
- while($row = mysqli_fetch_array($result)){
- $user = new User($row["idUser"], $row["name"], $row["email"], $row["user_name"], $row["password"], $row["type"], $row["active"], $row["idAdministrator"]);
- }
- echo "teste: ".$user->name;
- //close statement and connection
- $statement->close();
- Database::getInstance()->CloseConnection($this->connection);
- return $user;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement