BLACKSITE
:
216.73.216.50
:
174.141.238.224 / www.sscmp.com
:
Windows NT WIN-17DAGV8E5LJ 10.0 build 20348 (Windows Server 2016) AMD64
C:
/
Inetpub
/
vhosts
/
sscmp.com
/
httpdocs
/
library
/
Upload File:
files >> C:/Inetpub/vhosts/sscmp.com/httpdocs/library/database_lib.php
<?php /// pdo class Database{ // specify your own database credentials private $host = DB_SERVER; private $db_name = DB_NAME; private $username = DB_USER; private $password = DB_PASSWORD; public $pdo_con; // get the database connection public function getConnection(){ $this->pdo_con = null; try{ $this->pdo_con = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)); }catch(PDOException $exception){ echo "Connection error: " . $exception->getMessage(); } return $this->pdo_con; } } ///////// class CrudOperation extends Database{ private $conn; public function __construct($db){ $this->conn = $db; } public function check() { echo "Check"; exit; } //********************// Select Values //**********************// public function fetch_multi_row($table = "", $colomns = "", $join = "", $condition = "", $extra = "", $print_qry = false){ $qry = "select ".$colomns." from ".$table." "; if(trim($join) != ""){$qry .= " ".$join." ";} if(trim($condition) != ""){$qry .= " where (".$condition.") ";} if(trim($extra) != ""){$qry .= " ".$extra." ";} if($print_qry){echo $qry;} // print query // $stmt = $this->conn->prepare($qry); // $stmt->execute(); // //$this->conn = null; // return $stmt; // $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $this->conn->prepare($qry); $stmt->execute(); return $stmt; } public function fetch_distinct_row($table = "", $colomns = "", $join = "", $condition = "", $extra = "", $print_qry = false){ $qry = "select distinct ".$colomns." from ".$table." "; if(trim($join) != ""){$qry .= " ".$join." ";} if(trim($condition) != ""){$qry .= " where (".$condition.") ";} if(trim($extra) != ""){$qry .= " ".$extra." ";} if($print_qry){echo $qry;} // print query // $stmt = $this->conn->prepare($qry); // $stmt->execute(); // //$this->conn = null; // return $stmt; // $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $this->conn->prepare($qry); $stmt->execute(); return $stmt; } //********************// Select Query //**********************// public function fetch_query($qryTxt, $print_qry = false){ $qry = $qryTxt; if($print_qry){echo $qry;} // print query $stmt = $this->conn->prepare($qry); $stmt->execute(); //$this->conn = null; return $stmt; } /////******************///// public function fetch_single_row($table = "", $colomns = "", $join = "", $condition = "", $extra = "", $print_qry = false){ $qry = "select ".$colomns." from ".$table." "; //$qry="select GROUP_CONCAT(concat(concat("'",SUB_CODE),"'")) from studentdetail where (USER_ID = 'BUB17175634') limit 1"; if(trim($join) != ""){$qry .= " ".$join." ";} if(trim($condition) != ""){$qry .= " where (".$condition.") ";} if(trim($extra) != ""){$qry .= " ".$extra." ";} if($print_qry){echo $qry;} // print query $stmt = $this->conn->prepare($qry); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); //$this->conn = null; return $row; } ////**************//// public function fetch_single_value($table = "", $colomn = "", $condition = "", $extra = "", $print_qry = false){ $qry = "select ".$colomn." from ".$table." "; if(trim($condition) != ""){$qry .= " where (".$condition.") ";} if(trim($extra) != ""){$qry .= " ".$extra." ";} if($print_qry){echo $qry;} // print query $stmt = $this->conn->prepare($qry); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_BOTH); //$this->conn = null; return $row[0]; } public function fetch_query_value($qryTxt, $print_qry = false){ $qry = $qryTxt; if($print_qry){echo $qry;} // print query $stmt = $this->conn->prepare($qry); $stmt->execute(); //$this->conn = null; $row = $stmt->fetch(PDO::FETCH_BOTH); //$this->conn = null; return $row[0]; } //********************// Insert Values //**********************// public function insert_record($table = "", $colomns = "", $values = "", $print_qry = false){ $col_count = substr_count($colomns, ','); $values_array = explode("~", $values); $qry = "insert into ".$table." (".$colomns.") values ("; for($i = 0; $i <= $col_count; $i++){ if($i == 0){ $qry .= "?";}else{ $qry .= ",?";} } $qry .= ")"; //return $qry; try { $stmt = $this->conn->prepare($qry); //return $stmt; $ok=''; foreach ($values_array as $key => $value) { $stmt->bindParam(($key+1), $values_array[$key]); $ok.=$values_array[$key]; } //return $ok; $stmt->execute(); if($print_qry){$stmt->debugDumpParams();} // print query if($stmt->rowCount()>0){return true;}else{return false;} } catch (PDOException $e){ $e->getMessage(); return false; } } ///**********************////// public function update_record($table = "", $colomns = "", $values = "", $condition = "", $print_qry = false){ $colomn_array = explode(",", $colomns); $values_array = explode("~", $values); $qry = "update ".$table." set "; $read_qry = "update ".$table." set "; foreach($colomn_array as $key => $field){ if ($key == 0) { $qry .= $field.' = ?'; $read_qry .= $field.' = '.$values_array[$key]; } else { $qry .= ', '.$field.' = ?'; $read_qry .= ', '.$field.' = '.$values_array[$key]; } } if($condition != ""){ $qry .= "where (".$condition.") "; $read_qry .= "where (".$condition.") "; } try { $stmt = $this->conn->prepare($qry); $stmt->execute($values_array); if($print_qry){ //$stmt->debugDumpParams(); echo $read_qry; } if($stmt->rowCount()>0){return true;}else{return false;} } catch (PDOException $e){ $e->getMessage(); return false; } } ////***************************///// public function delete_record($table = "", $condition = "", $print_qry = false){ $qry = "delete from ".$table." "; if($condition != ""){ $qry .= "where (".$condition.") "; } try { $stmt = $this->conn->prepare($qry); $stmt->execute(); if($print_qry){$stmt->debugDumpParams();} if($stmt->rowCount()>0){return true;}else{return false;} } catch (PDOException $e){ $e->getMessage(); return false; } } ////////**********************////////////// } /////////////////************************ function backup_database($tables = '*',$debug="false"){ //get all of the tables if($tables == '*') { $tables = array(); $result = mysqli_query($sql,'SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = "`".$row[0]."`"; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } if($debug=="true") { print_r($tables); } //cycle through foreach($tables as $table) { $result = mysqli_query($sql,'SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysqli_query($sql,'SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } if($debug=="true") { echo $return; } // We'll be outputting a PDF $sqlfname='../backup/db-backup-'.date("d_m_Y_H_i_s",time()+(5.5*60*60)).'.sql'; $zipfname='../backup/db-backup-'.date("d_m_Y_H_i_s",time()+(5.5*60*60)).'.zip'; $downfname="db-backup-".date("d-m-Y H:i:s",time()+(5.5*60*60)).".zip"; $handle = fopen($sqlfname,'w+'); fwrite($handle,$return); fclose($handle); $files =array ($sqlfname); $zipTest = new zipfile(); $zipTest->add_file($sqlfname, $sqlfname); // Return Zip File to Browser Header("Content-type: application/octet-stream"); Header ("Content-disposition: attachment; filename=" . $downfname ); echo $zipTest->file(); //create_zip($files,$zipfname); // echo $zipfname; //header('Content-type: application/octet-stream;'); //header('Content-Disposition: attachment; filename="'.$downfname.'"'); //readfile($zipfname); unlink($sqlfname); //unlink($zipfname); }