Guest User

Untitled

a guest
Jun 25th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2. class Database {
  3.  
  4. private $host;
  5. private $username;
  6. private $password;
  7. private $database;
  8. private $con;
  9. private $table;
  10.  
  11. /**
  12. * @param String $host
  13. * @param String $user
  14. * @param String $pass
  15. * @param String $db
  16. * @param String $table
  17. */
  18. public function __construct($host, $user, $pass, $db, $table) {
  19. $this->host = $host;
  20. $this->username = $user;
  21. $this->password = $pass;
  22. $this->database = $db;
  23. $this->table = $table;
  24. }
  25.  
  26. public function connect() {
  27. $this->con = new PDO('mysql:host='.$this->host.';dbname='.$this->database.';charset=utf8', $this->username, $this->password);
  28. $this->con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
  29. $this->con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  30. }
  31.  
  32. public function getCon() {
  33. return $this->con;
  34. }
  35.  
  36. public function countUsers($iron) {
  37. $stmt = $this->con->prepare("SELECT * FROM $this->table LIMIT 500");
  38. $stmt->execute();
  39. return count($stmt->fetchAll(PDO::FETCH_ASSOC));
  40. }
  41.  
  42. public function getUser($name) {
  43. $stmt = $this->con->prepare("SELECT * FROM $this->table WHERE username=:name");
  44. $stmt->bindParam(":name", $name);
  45. $stmt->execute();
  46. return $stmt->fetch(PDO::FETCH_ASSOC);
  47. }
  48.  
  49. public function getAllUsers($skill, $min) {
  50. $stmt = $this->con->prepare("SELECT * FROM $this->table ORDER BY $skill DESC LIMIT $min, 25");
  51. $stmt->execute();
  52. return $stmt->fetchAll(PDO::FETCH_ASSOC);
  53. }
  54.  
  55. public function getRank($user, $skill) {
  56. $sk = strtolower($skill)."_xp";
  57. $stmt = $this->con->prepare("SELECT * FROM $this->table ORDER BY $sk DESC LIMIT 200");
  58. $stmt->execute();
  59. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  60. $count = 1;
  61. foreach ($results as $entry) {
  62. if (strtolower($entry['username']) == strtolower($user)) {
  63. return $count;
  64. }
  65. $count++;
  66. }
  67. }
  68.  
  69. }
  70. ?>
Add Comment
Please, Sign In to add comment