Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. <?php
  2. class DB{
  3. private $host = 'mysql.hostinger.ph';
  4. private $db = 'u345259216_isys';
  5. private $username = 'u345259216_isys';
  6. private $password = 'upanginfosys';
  7. private $conn;
  8. private $stmt;
  9.  
  10. public function __construct()
  11. {
  12. try{
  13. $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db.'',$this->username,$this->password);
  14. $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  16. }
  17. catch(PDOException $e){
  18. die();
  19. $e->getMessage();
  20. echo $e;
  21. }
  22. }
  23.  
  24. public function insert($table,$fields,$bv,$values)
  25. {
  26. $this->stmt = $this->conn->prepare("INSERT INTO ".$table."(".implode(',',$fields).") VALUES(".implode(',',$bv).") ");
  27. for($x=0; $x<count($values); $x++)
  28. {
  29. $this->stmt->bindValue($bv[$x],$values[$x]);
  30. }
  31. $this->stmt->execute() or die(print_r(errorInfo(),true));
  32. #$this->conn = null;
  33. // var_dump($this->stmt);
  34.  
  35. }
  36.  
  37. public function select($where,$field,$table,$tblfield,$val)
  38. {
  39. if($where === 1){
  40. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val);
  41. $this->stmt->execute() or die(print_r(errorInfo(),true));
  42. // var_dump($x->execute());
  43. return $this->stmt;
  44. #$this->conn = null;
  45. }else{
  46. $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table."");
  47. $this->stmt->execute() or die(print_r(errorInfo(),true));
  48. // var_dump($x->execute());
  49. return $this->stmt;
  50. #$this->conn = null;
  51. }
  52. }
  53.  
  54. public function selectOrderBy($where,$field,$table,$tblfield,$val,$selector,$ascordesc)
  55. {
  56. if($where === 1){
  57. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. "ORDER BY ".$selector. " ".$ascordesc);
  58. $this->stmt->execute() or die(print_r(errorInfo(),true));
  59. // var_dump($x->execute());
  60. return $this->stmt;
  61. #$this->conn = null;
  62. }else{
  63. $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table." ORDER BY ".$selector. " ".$ascordesc);
  64. $this->stmt->execute() or die(print_r(errorInfo(),true));
  65. // var_dump($x->execute());
  66. return $this->stmt;
  67. #$this->conn = null;
  68. }
  69. }
  70.  
  71. public function selectOrderByLimit($where,$field,$table,$tblfield,$val,$selector,$ascordesc,$limit)
  72. {
  73. if($where === 1){
  74. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. "ORDER BY ".$selector. " ".$ascordesc." LIMIT ".$limit);
  75. $this->stmt->execute() or die(print_r(errorInfo(),true));
  76. // var_dump($x->execute());
  77. return $this->stmt;
  78. #$this->conn = null;
  79. }else{
  80. $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table." ORDER BY ".$selector. " ".$ascordesc." LIMIT ".$limit);
  81. $this->stmt->execute() or die(print_r(errorInfo(),true));
  82. // var_dump($x->execute());
  83. return $this->stmt;
  84. #$this->conn = null;
  85. }
  86. }
  87.  
  88. public function selectExcept($where,$field,$table,$tblfield,$val)
  89. {
  90. if($where === 1){
  91. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " != ".$val);
  92. $this->stmt->execute() or die(print_r(errorInfo(),true));
  93. // var_dump($x->execute());
  94. return $this->stmt;
  95. #$this->conn = null;
  96. }else{
  97. $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table."");
  98. $this->stmt->execute() or die(print_r(errorInfo(),true));
  99. // var_dump($x->execute());
  100. return $this->stmt;
  101. #$this->conn = null;
  102. }
  103. }
  104.  
  105. public function selectAnd($field,$table,$f1,$v1,$f2,$v2)
  106. {
  107. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$f1. " = ".$v1. " AND " .$f2. " = ".$v2. "");
  108. $this->stmt->execute() or die(print_r(errorInfo(),true));
  109. return $this->stmt;
  110. #$this->conn = null;
  111. }
  112.  
  113.  
  114. public function selectWithLimit($where,$field,$table,$tblfield,$val,$limit)
  115. {
  116. if($where === 1)
  117. {
  118. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. " LIMIT ".$limit." ");
  119. $this->stmt->execute() or die(print_r(errorInfo(),true));
  120. return $this->stmt;
  121. #$this->conn = null;
  122. }
  123. else{
  124. $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." LIMIT ".$limit." ");
  125. $this->stmt->execute() or die(print_r(errorInfo(),true));
  126. return $this->stmt;
  127. #$this->conn = null;
  128. }
  129. }
  130.  
  131. public function selectWithCount($where,$table,$tblfield,$val)
  132. {
  133. if($where === 1)
  134. {
  135. $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table." WHERE " .$tblfield. " = ".$val);
  136. $this->stmt->execute() or die(print_r(errorInfo(),true));
  137. return $this->stmt;
  138. #$this->conn = null;
  139. }
  140. else{
  141. $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table."");
  142. $this->stmt->execute() or die(print_r(errorInfo(),true));
  143. return $this->stmt;
  144. #$this->conn = null;
  145. }
  146. }
  147. public function selectWithCountAnd($table,$f1,$v1,$f2,$v2)
  148. {
  149. $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table." WHERE " .$f1. " = ".$v1." AND ".$f2. " = ".$v2."");
  150. $this->stmt->execute() or die(print_r(errorInfo(),true));
  151. return $this->stmt;
  152. #$this->conn = null;
  153. }
  154.  
  155. #select * FROM tblregistration left join tblaccount on tblregistration.lastname = tblaccount.password where tblaccount.appnum = '57ce45ea5fc4f'
  156.  
  157. public function edit($table,$colWithVal,$field,$fieldval)
  158. {
  159. $this->stmt =$this->conn->prepare("UPDATE ".$table." SET ".implode(',',$colWithVal)." WHERE ".$field." = ".$fieldval);
  160. $this->stmt->execute() or die(print_r(errorInfo(),true));
  161. #$this->conn = null;
  162. }
  163.  
  164.  
  165. public function delete($table,$column,$valcol)
  166. {
  167. $this->stmt = $this->conn->prepare("DELETE FROM ".$table." WHERE ".$column." = ".$valcol);
  168. $this->stmt->execute();
  169. #$this->conn = null;
  170. }
  171.  
  172. public function login($table,$field1,$value1,$field2,$value2)
  173. {
  174. $this->stmt = $this->conn->prepare("SELECT COUNT(*) from ".$table." where ".$field1." = '".$value1."' AND ".$field2."='".$value2."' ");
  175. $this->stmt->execute() or die(print_r(errorInfo(),true));
  176. if($this->stmt->fetchColumn() > 0) {
  177. $this->stmt = $this->conn->prepare("SELECT * from ".$table." where ".$field1." = '".$value1."' AND ".$field2."='".$value2."' ");
  178. $this->stmt->execute() or die(print_r(errorInfo(),true));
  179. return $this->stmt;
  180. #$this->conn = null;
  181. }else{
  182. echo "<br><div class='alert alert-danger role=alert'><strong>Authentication Failed.<br></strong> Incorrect login credentials.</div>";}
  183. }
  184.  
  185. public function countRecords($table)
  186. {
  187. $this->stmt = $this->conn->prepare("SELECT COUNT(*) from ".$table);
  188. $this->stmt->execute() or die(print_r(errorInfo(),true));
  189. return $this->stmt->fetchColumn();
  190. #$this->conn = null;
  191. }
  192. }
  193.  
  194. class Cms extends DB{
  195. public function redirectWithALert($location)
  196. {
  197. header('Location: '.$location.'');
  198. }
  199. public function embedAlertSuccess($parag)
  200. {
  201. echo "<br><div class='alert alert-success alert-dismissible' role='alert'>
  202. <button type='button' class='close' data-dismiss='alert' aria-label='Close'><spanaria-hidden='true'>&times;</span></button>
  203. <strong>Success!<br></strong> ".$parag.".
  204. </div>";
  205. }
  206. public function embedWarningUD($strong,$parag)
  207. {
  208. echo "<div class='alert alert-danger' role='alert'> <strong>".$strong."<br></strong> ".$parag.".</div";
  209. }
  210. public function embedWarningDM($strong,$parag)
  211. {
  212. echo "<br><div class='alert alert-warning alert-dismissible' role='alert'>
  213. <button type='button' class='close' data-dismiss='alert' aria-label='Close'><spanaria-hidden='true'>&times;</span></button>
  214. <strong>".$strong."<br></strong> ".$parag.".
  215. </div>";
  216. }
  217. public function logout($loc)
  218. {
  219. session_start();
  220. session_destroy();
  221. header("Location: $loc");
  222. }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement