MINI Sh3ll
<?php
class database {
public $connection;
public function __construct(){
$this->connection = new mysqli(MYSQL_SERVER, MYSQL_LOGINID, MYSQL_PASSWORD, MYSQL_DATABASE);
return $this->connection;
}
private function execute_query($query){
if($query == '') return false;
$this->connection->query('SET character_set_results=utf8');
//$this->connection->query('SET names=utf8');
$this->connection->query('SET character_set_client=utf8');
$this->connection->query('SET character_set_connection=utf8');
$this->connection->query('SET character_set_results=utf8');
$this->connection->query('SET collation_connection=utf8_general_ci');
$result = $this->connection->query($query);
return $result;
}
public function get_records($sql){
if($sql == '') return '';
$arrRetvalue = '';
$result = $this->execute_query($sql);
$totrecord = $result->num_rows;
if($totrecord > 0) {
$arrRetvalue = array();
while($row = $result->fetch_assoc()){
$arrRetvalue[] = $row;
}
}
return is_array($arrRetvalue) ? $arrRetvalue : false;
}
public function get_total_record($sql){
if($sql == '') return '';
$result = $this->execute_query($sql);
$totrecord = mysql_num_rows($result);
return $totrecord;
}
public function saveRecords($sql){
if($sql == '') return '';
$result = $this->execute_query($sql);
$currid = mysqli_insert_id($this->connection);
return $currid;
}
public function saveRecordsNew($table = '', $insert_data = ''){
if($table == '' || $insert_data == '') return false;
$sql = "insert into ".$table." (".implode(', ', array_keys($insert_data)).") values( ";
$inserts = [];
foreach ($insert_data as $akey => $avalue) {
$inserts[] = "'".mysql_escape($this->connection, $avalue)."'";
}
$sql .= implode(', ', $inserts);
$sql .= ')';
$result = $this->execute_query($sql);
$currid = mysqli_insert_id($this->connection);
return $currid;
}
public function newUpdateRecords($table,$data,$where_filed,$where_value){
if($table == '' || $data == '' || $where_filed == '' || $where_value == '' ) return false;
$sql ="update ".$table." set ";
foreach ($data as $key => $value) {
$sql .= $key." = '".mysql_escape($this->connection, $value)."',";
}
$sql = rtrim($sql,',');
$sql .= " where ".$where_filed." = '".$where_value."'";
$result = $this->execute_query($sql);
$currid = mysqli_insert_id($this->connection);
return $currid;
}
public function deleteRecords($sql){
if($sql == '') return '';
$result = $this->execute_query($sql);
return $result;
}
public function closeConnection()
{
$this->connection->close();
}
}
?>
OHA YOOOO