Advertisement
Guest User

Untitled

a guest
Nov 6th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. class Usercontrol{
  5. // handles DB access and modifies the user database based on the user model
  6. // TODO: separate class for db access ?
  7.  
  8. private $dsn = 'mysql:dbname=praktikum;host=127.0.0.1';
  9. private $user = 'root';
  10. private $password = 'test123';
  11. private $connection;
  12.  
  13. public function __construct(){
  14. $this->dsn = 'mysql:dbname=praktikum;host=127.0.0.1';
  15. $this->user = 'root';
  16. $this->password = 'test123';
  17. $this->connection = new PDO($this->dsn, $this->user);
  18. }
  19.  
  20. private function change_db($dbname, $user){
  21. $this->dsn = 'mysql:$dbname=praktikum;host=127.0.0.1';
  22. $this->connection.close();
  23. $this->connection = new PDO($this->dsn, $this->user);
  24. }
  25.  
  26. public function createNewUser($mail, $nick, $password){
  27. try
  28. {
  29. //TODO: check for existing user!
  30. // SELECT COUNT(nick) AS number FROM user WHERE nick="Flo"
  31. /** $san_mail = filter_var($mail, FILTER_SANITIZE_SPECIAL_CHARS);
  32. $san_nick = filter_var($nick, FILTER_SANITIZE_SPECIAL_CHARS);
  33. $san_password = filter_var($password, FILTER_SANITIZE_SPECIAL_CHARS);
  34.  
  35. try
  36. {
  37. $statement = $this->conenction->prepare("SELECT COUNT(nick) AS number FROM user WHERE nick="Flo"");
  38. }
  39. //$statement = $this->conenction->prepare("SELECT COUNT(nick) AS number FROM user WHERE nick="Flo"");
  40. **/
  41. $statement = $this->connection->prepare("INSERT INTO USER (email, nick, password) VALUES (?, ?, ?)");
  42. $statement->execute(array($mail, $nick, $password));
  43. }
  44. catch (Exception $e){
  45. echo "<br>ERROR: $e</br>";
  46. }
  47. }
  48.  
  49. public function getUserInfo($mail, $password){
  50. //TODO: print error message if password is wrong
  51.  
  52. $this->connection = new PDO($this->dsn, $this->user);
  53. $san_mail = filter_var($mail, FILTER_SANITIZE_SPECIAL_CHARS);
  54. $san_password = filter_var($password, FILTER_SANITIZE_SPECIAL_CHARS);
  55.  
  56. try{
  57. $statement = $this->connection->prepare('SELECT * FROM user WHERE email="' . $san_mail . '" AND password="' . $san_password .'"');
  58. echo "<br> san_email: $san_mail<br> san_passwd: $san_password <br>";
  59. $statement->execute();
  60. $result = $statement->fetchAll();
  61. }
  62. catch(Exception $e){
  63. echo "<div><b>ERROR<b> in getUserInfo (user.control) -> $e </div>";
  64. return $e;
  65. }
  66. return $result;
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement