Advertisement
Guest User

Untitled

a guest
Sep 17th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. class hb {
  3.  
  4. private $pdo;
  5.  
  6. public function __construct() {
  7. ob_start();
  8. try {
  9. $this->pdo = new PDO('mysql:host=localhost;dbname=crawler', 'root', 'PASSWORD');
  10. } catch(PDOException $e) {
  11. echo 'ERROR: ' . $e->getMessage();
  12. }
  13. }
  14.  
  15. private function sql($sql, $a = '') {
  16. $zooi = $this->pdo->prepare($sql);
  17. $e = $zooi->execute();
  18. switch($a) {
  19. case "fetch":
  20. return (object) $zooi->fetch(PDO::FETCH_ASSOC);
  21. case "fetchAll":
  22. return (object) $zooi->fetchAll(PDO::FETCH_ASSOC);
  23. case "count":
  24. return $zooi->rowCount();
  25. case "bool":
  26. return $e;
  27. case "id":
  28. return $this->pdo->lastInsertId();
  29. case "":
  30. return $zooi;
  31. }
  32. }
  33.  
  34. public function latest_game() {
  35. return (array) $this->sql("SELECT * FROM apps WHERE id IN (SELECT MAX(id) FROM apps)", 'fetch');
  36. }
  37.  
  38. public function preg_file($regex, $url, $filter = PREG_SET_ORDER) {
  39. $f = str_replace("?", "", utf8_decode(file_get_contents($url)));
  40. preg_match_all($regex, $f, $m, $filter);
  41. return $m;
  42. }
  43.  
  44. public function add_to_db($a) {
  45. if(!is_array($a) || empty($a)) {
  46. return false;
  47. }
  48.  
  49. foreach($a as $k => $app) {
  50. $this->sql("INSERT INTO apps (steam_id, name, type) VALUES ('".$app[1]."', '".$app[3]."', '".$app[2]."')");
  51. }
  52. }
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement