Advertisement
Guest User

Untitled

a guest
Aug 14th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. require ("identifier.php");
  3. class Database
  4. {
  5. private $HOST = HOST;
  6. private $USER = USER;
  7. private $PASS = PASS;
  8. private $_TABLE = TABLE;
  9. private $_connect,$_error,$_stmt;
  10. function __construct()
  11. {
  12. // Define attributes for PDO instance
  13. $ATTR = array(
  14. PDO::ATTR_PERSISTENT => true,
  15. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  16. );
  17. // New PDO instance
  18. try{
  19. $this->_connect = new PDO($this->HOST, $this->USER, $this->PASS, $ATTR);
  20. } catch (PDOException $e) {
  21. $this->_error = $e->getMessage();
  22. }
  23. }
  24. //return table method
  25. public function table() {
  26. return $this->_TABLE;
  27. }
  28. // Query method
  29. public function query($query){
  30. $this->_stmt = $this->_connect->prepare($query);
  31. }
  32. // execute method
  33. public function execute(){
  34. return $this->_stmt->execute();
  35. }
  36. // fetch method
  37. public function fetch(){
  38. $this->execute();
  39. return $this->_stmt->fetch(PDO::FETCH_ASSOC);
  40. }
  41. // fetchAll method
  42. public function fetchAll(){
  43. $this->execute();
  44. return $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
  45. }
  46. // rowCount method
  47. public function rowCount(){
  48. return $this->_stmt->rowCount();
  49. }
  50. // lastInsertId method
  51. public function lastInsertId(){
  52. return $this->_connect->lastInsertId();
  53. }
  54. // bindParam method
  55. public function bindParam($param, $value, $type = null){
  56. if(is_null($type)){
  57. switch (true) {
  58. case is_int($value):
  59. $type = PDO::PARAM_INT;
  60. break;
  61. case is_bool($value):
  62. $type = PDO::PARAM_BOOL;
  63. break;
  64. case is_null($value):
  65. $type = PDO::PARAM_NULL;
  66. break;
  67. default:
  68. $type = PDO::PARAM_STR;
  69. }
  70. }
  71. $this->_stmt->bindvalue($param,$value,$type);
  72. }
  73. // closeCursor method
  74. public function closeCursor() {
  75. return $this->_stmt->closeCursor();
  76. }
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement