main/build/database/repo/user.php

51 lines
1.0 KiB
PHP

<?php
namespace database\repo;
use \database\core\Repo_i;
class user extends Repo_i{
public function getAll(){
/* (1) Statement */
$st = $this->pdo->query("SELECT * FROM user ORDER BY username ASC");
/* (2) Fetched data */
return $st->fetchAll();
}
public function getById(int $id_user){
/* (1) Prepare Statement */
$pst = $this->pdo->prepare("SELECT * FROM user WHERE id_user = :id_user");
/* (2) Bind variables */
$pst->bindParam(':id_user', $id_user, \PDO::PARAM_INT);
/* (3) Execute */
if( !$pst->execute() ) return false; // if error -> send FALSE
/* (4) Fetched data */
return $pst->fetchAll();
}
public function getByMail(String $mail){
/* (1) Prepare Statement */
$pst = $this->pdo->prepare("SELECT * FROM user WHERE mail = :mail");
/* (2) Bind variables */
$pst->bindParam(':mail', $mail, \PDO::PARAM_STR, 50);
/* (3) Execute */
if( !$pst->execute() ) return false; // if error -> send FALSE
/* (4) Fetched data */
return $pst->fetchAll();
}
}