Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. <?php
  2.  
  3. require("database.php");
  4.  
  5. // User class
  6. class user {
  7.  
  8. // Attributes
  9. public $uid,$ucognome,$unome,$uemail,$utel;
  10.  
  11. private $db = null;
  12.  
  13. function __construct() {
  14. $this->db = new Database();
  15. }
  16.  
  17. // Insert user
  18. public function insert(){
  19. $sql = "INSERT INTO users (cognome,nome,email,telefono)
  20. VALUES('".$this->ucognome."', '".$this->unome."','".$this->uemail."'
  21. ,'".$this->utel."')";
  22.  
  23. $this->db->run($sql);
  24.  
  25. }
  26.  
  27. // Delete user
  28. public function delete(){
  29. $sql = "DELETE FROM users WHERE id=". $this->uid;
  30. $this->db->run($sql);
  31. }
  32.  
  33.  
  34. // Update user
  35. public function update(){
  36. $sql = "UPDATE users SET cognome= '".$this->ucognome."',
  37. nome='".$this->unome."',
  38. email='".$this->uemail."',
  39. telefono='".$this->utel."'
  40.  
  41. WHERE id ='".$this->uid."'";
  42.  
  43. $this->db->run($sql);
  44. }
  45.  
  46. // Display users
  47. public function display(){
  48. $temp_arr = array();
  49.  
  50. $res = $this->db->run("SELECT * FROM users ORDER by cognome,nome ");
  51.  
  52. $count=$this->db->rowCount();
  53.  
  54. while($row = $this->db->fetchArray()) {
  55. $temp_arr[] =$row;
  56. }
  57. return $temp_arr;
  58.  
  59. }
  60.  
  61.  
  62. // get id upload
  63. public function getid(){
  64. $nome = $this->unome;
  65. $cognome = $this->ucognome;
  66. $email = $this->uemail;
  67. $telefono = $this->utel;
  68. $sql = "SELECT id FROM users WHERE nome='$nome' and cognome='$cognome' and email='$email' and telefono='$telefono'";
  69. var_dump($this->db->prepare($sql)->execute());
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. // Get user by id (update)
  78. public function getUserById($uid){
  79. $temp_arr = array();
  80.  
  81. $res = $this->db->run("SELECT * FROM users WHERE id=$uid");
  82.  
  83. $userDetails = $this->db->fetchArray();
  84.  
  85. return $userDetails;
  86. }
  87. }
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement