Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DB{
- private $host = 'mysql.hostinger.ph';
- private $db = 'u345259216_isys';
- private $username = 'u345259216_isys';
- private $password = 'upanginfosys';
- private $conn;
- private $stmt;
- public function __construct()
- {
- try{
- $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->db.'',$this->username,$this->password);
- $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- }
- catch(PDOException $e){
- die();
- $e->getMessage();
- echo $e;
- }
- }
- public function insert($table,$fields,$bv,$values)
- {
- $this->stmt = $this->conn->prepare("INSERT INTO ".$table."(".implode(',',$fields).") VALUES(".implode(',',$bv).") ");
- for($x=0; $x<count($values); $x++)
- {
- $this->stmt->bindValue($bv[$x],$values[$x]);
- }
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- #$this->conn = null;
- // var_dump($this->stmt);
- }
- public function select($where,$field,$table,$tblfield,$val)
- {
- if($where === 1){
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }else{
- $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table."");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectOrderBy($where,$field,$table,$tblfield,$val,$selector,$ascordesc)
- {
- if($where === 1){
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. "ORDER BY ".$selector. " ".$ascordesc);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }else{
- $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table." ORDER BY ".$selector. " ".$ascordesc);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectOrderByLimit($where,$field,$table,$tblfield,$val,$selector,$ascordesc,$limit)
- {
- if($where === 1){
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. "ORDER BY ".$selector. " ".$ascordesc." LIMIT ".$limit);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }else{
- $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table." ORDER BY ".$selector. " ".$ascordesc." LIMIT ".$limit);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectExcept($where,$field,$table,$tblfield,$val)
- {
- if($where === 1){
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " != ".$val);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }else{
- $this->stmt = $this->conn->prepare("SELECT ".$field."FROM ".$table."");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- // var_dump($x->execute());
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectAnd($field,$table,$f1,$v1,$f2,$v2)
- {
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$f1. " = ".$v1. " AND " .$f2. " = ".$v2. "");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- public function selectWithLimit($where,$field,$table,$tblfield,$val,$limit)
- {
- if($where === 1)
- {
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." WHERE " .$tblfield. " = ".$val. " LIMIT ".$limit." ");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- else{
- $this->stmt = $this->conn->prepare("SELECT ".$field." FROM ".$table." LIMIT ".$limit." ");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectWithCount($where,$table,$tblfield,$val)
- {
- if($where === 1)
- {
- $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table." WHERE " .$tblfield. " = ".$val);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- else{
- $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table."");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- }
- public function selectWithCountAnd($table,$f1,$v1,$f2,$v2)
- {
- $this->stmt = $this->conn->prepare("SELECT COUNT(*) FROM ".$table." WHERE " .$f1. " = ".$v1." AND ".$f2. " = ".$v2."");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }
- #select * FROM tblregistration left join tblaccount on tblregistration.lastname = tblaccount.password where tblaccount.appnum = '57ce45ea5fc4f'
- public function edit($table,$colWithVal,$field,$fieldval)
- {
- $this->stmt =$this->conn->prepare("UPDATE ".$table." SET ".implode(',',$colWithVal)." WHERE ".$field." = ".$fieldval);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- #$this->conn = null;
- }
- public function delete($table,$column,$valcol)
- {
- $this->stmt = $this->conn->prepare("DELETE FROM ".$table." WHERE ".$column." = ".$valcol);
- $this->stmt->execute();
- #$this->conn = null;
- }
- public function login($table,$field1,$value1,$field2,$value2)
- {
- $this->stmt = $this->conn->prepare("SELECT COUNT(*) from ".$table." where ".$field1." = '".$value1."' AND ".$field2."='".$value2."' ");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- if($this->stmt->fetchColumn() > 0) {
- $this->stmt = $this->conn->prepare("SELECT * from ".$table." where ".$field1." = '".$value1."' AND ".$field2."='".$value2."' ");
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt;
- #$this->conn = null;
- }else{
- echo "<br><div class='alert alert-danger role=alert'><strong>Authentication Failed.<br></strong> Incorrect login credentials.</div>";}
- }
- public function countRecords($table)
- {
- $this->stmt = $this->conn->prepare("SELECT COUNT(*) from ".$table);
- $this->stmt->execute() or die(print_r(errorInfo(),true));
- return $this->stmt->fetchColumn();
- #$this->conn = null;
- }
- }
- class Cms extends DB{
- public function redirectWithALert($location)
- {
- header('Location: '.$location.'');
- }
- public function embedAlertSuccess($parag)
- {
- echo "<br><div class='alert alert-success alert-dismissible' role='alert'>
- <button type='button' class='close' data-dismiss='alert' aria-label='Close'><spanaria-hidden='true'>×</span></button>
- <strong>Success!<br></strong> ".$parag.".
- </div>";
- }
- public function embedWarningUD($strong,$parag)
- {
- echo "<div class='alert alert-danger' role='alert'> <strong>".$strong."<br></strong> ".$parag.".</div";
- }
- public function embedWarningDM($strong,$parag)
- {
- echo "<br><div class='alert alert-warning alert-dismissible' role='alert'>
- <button type='button' class='close' data-dismiss='alert' aria-label='Close'><spanaria-hidden='true'>×</span></button>
- <strong>".$strong."<br></strong> ".$parag.".
- </div>";
- }
- public function logout($loc)
- {
- session_start();
- session_destroy();
- header("Location: $loc");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement