Advertisement
Hirsw0w

Untitled

Oct 11th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Data short summary.
  5. *
  6. * Data description.
  7. *
  8. * @version 1.0
  9. * @author liran
  10. */
  11. class Data
  12. {
  13. protected $dbh;
  14. protected $stmt;
  15.  
  16. public function __construct(){
  17. $this->dbh = new PDO("mysql:host=".DB_HOST.";dbname=". DB_NAME, DB_USER, DB_PASS);
  18. }
  19.  
  20. public function query($query){
  21. $this->stmt = $this->dbh->prepare($query);
  22. }
  23.  
  24. //Binds the prep statement
  25. public function bind($param, $value, $type = null){
  26. if (is_null($type)) {
  27. switch (true) {
  28. case is_int($value):
  29. $type = PDO::PARAM_INT;
  30. break;
  31. case is_bool($value):
  32. $type = PDO::PARAM_BOOL;
  33. break;
  34. case is_null($value):
  35. $type = PDO::PARAM_NULL;
  36. break;
  37. default:
  38. $type = PDO::PARAM_STR;
  39. }
  40. }
  41. $this->stmt->bindValue($param, $value, $type);
  42. }
  43.  
  44. public function execute(){
  45. $this->stmt->execute();
  46. }
  47.  
  48. public function resultSet(){
  49. $this->execute();
  50. return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  51. }
  52.  
  53. public function lastInsertId(){
  54. return $this->dbh->lastInsertId();
  55. }
  56.  
  57. public function single(){
  58. $this->execute();
  59. return $this->stmt->fetch(PDO::FETCH_ASSOC);
  60. }
  61.  
  62. public function clearstr($str) {
  63. return $this->dbh->quote($str);
  64. }
  65.  
  66. private function isInteger($input){
  67. return(ctype_digit(strval($input)));
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement