%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
class Test extends MY_Controller {
function __construct() {
parent::__construct();
$this->filename="test-dump.sql";
}
function testemail(){
send_email("sat.web1989@gmail.com", "Testing Multi1", "Hello"); //,satyendrayadav1989@gmail.com
}
function testt(){
//$mysqli=new mysqli($this->db->hostname, $this->db->username, $this->db->password, $this->db->database);
//$result=$mysqli->query("SELECT * FROM applications", MYSQLI_USE_RESULT);
$result=$this->dba->unbuffered_query("SELECT * FROM applications");
pr($result);
// die;
// $mysqli=$this->dba->mysqli();
// $result=$mysqli->query("SELECT * FROM applications", MYSQLI_USE_RESULT);
if($result) {
while ($row = $result->fetch_assoc()) {
}
}
//pr($result);
/*$filename="test.txt";
header('Content-Type: text/plain; charset=UTF-8');
header('Content-Disposition: attachment; filename="'.$filename.'";');
$f=fopen('php://output', 'w');*/
if($result) {
$c=1;
while ($row = $result->fetch_assoc()) {
if($c>1000000){
//break;
}
//fwrite($f, json_encode($row)."\n");
$c++;
}
}
//fclose($f);
}
function dump_headers($type) {
$output = $type;
$ext = "sql";
header("Content-Type: " .
($output == "gz" ? "application/x-gzip" :
($ext == "tar" ? "application/x-tar" :
($ext == "sql" || $output != "file" ? "text/plain" : "text/csv") . "; charset=utf-8"
)));
if ($output == "gz") {
ob_start('ob_gzencode', 1e6);
}
return $ext;
}
function set_output($type='file', $identifier="tmpdwn"){
$output = $type;
$return = $this->dump_headers($type);
if ($output != "text") {
header("Content-Disposition: attachment; filename=$identifier" . ".$return" . ($output != "file" && !preg_match('~[^0-9a-z]~', $output) ? ".$output" : ""));
}
session_write_close();
ob_flush();
flush();
}
function output($str){
//write_file(FCPATH.$this->filename, $str, "a");
echo $str;
}
function unconvert_field($field, $return) {
if (preg_match("~binary~", $field["type"])) {
$return = "UNHEX($return)";
}
if ($field["type"] == "bit") {
$return = "CONV($return, 2, 10) + 0";
}
if (preg_match("~geometry|point|linestring|polygon~", $field["type"])) {
$return = (min_version(8) ? "ST_" : "") . "GeomFromText($return)";
}
return $return;
}
function number_type() {
return '((?<!o)int(?!er)|numeric|real|float|double|decimal|money)'; // not point, not interval
}
function q($v){
return $this->db->escape($v);
}
function idf_escape($idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
function dump_table($table, $style, $is_view = 0){
$create="";
if($is_view){
}else{
$create.=array_values($this->db->query("SHOW CREATE TABLE ".$table)->row_array())[1].";\n";
}
if ($style && $create) {
if ($style == "DROP+CREATE" || $is_view) {
$create="DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " .$table. ";\n".$create."\n\n";
}
$this->output($create);
}
}
function dump_data($table, $style){
$max_packet = 1048576; //1048576
$result=$this->db->simple_query("SELECT * FROM $table");
if(!$result){
return;
}
$tbl_fields=$this->db->list_fields($table);
$insert = "";
$buffer = "";
$keys = array();
$suffix = "";
while($row = mysqli_fetch_assoc($result)) {
if(!$keys){
$values = array();
$i=0;
foreach ($row as $val) {
/*$field = $result->fetch_field();
$keys[] = $this->idf_escape($field->name);
$key = $this->idf_escape($field->name);*/
$keys[]=$this->idf_escape($tbl_fields[$i]);
$key=$this->idf_escape($tbl_fields[$i]);
$values[] = "$key = VALUES($key)";
$i++;
}
$suffix=";\n";
}
if(!$insert){
$insert = "INSERT INTO " . $table . " (" . implode(", ", $keys) . ") VALUES";
}
foreach($row as $key => $val){
$field = $fields[$key];
$row[$key] = ($val !== null
? $this->unconvert_field($field, preg_match($this->number_type(), $field["type"]) && $val != '' && !preg_match('~\[~', $field["full_type"]) ? $val : $this->q(($val === false ? 0 : $val)))
: "NULL"
);
}
$s = ($max_packet ? "\n" : " ") . "(" . implode(",\t", $row) . ")";
if (!$buffer) {
$buffer = $insert . $s;
} elseif ((strlen($buffer) + 4 + strlen($s) + strlen($suffix)) < $max_packet) { // 4 - length specification
$buffer .= ",$s";
} else {
$this->output($buffer . $suffix);
$buffer = $insert . $s;
}
}
if($buffer){
$this->output($buffer . $suffix);
}
}
function index(){
ini_set('memory_limit', '-1');
set_time_limit(0);
del_file(FCPATH.$this->filename);
$db=$this->db->database;
$tables=$this->db->list_tables();
$config=[
'output'=>'file', //gz, file
'format'=>'sql',
'db_style'=>'',
'routines'=>1,
'events'=>1,
'triggers'=>1,
'table_style'=>'DROP+CREATE',
'data_style'=>'INSERT',
'tables'=>$tables,
'data'=>$tables,
];
//$tables = array_flip((array) $config["tables"]) + array_flip((array) $config["data"]);
$this->set_output($config['output'], "test");
$head="SET NAMES utf8; SET time_zone = '+00:00';\nSET foreign_key_checks = 0;\nSET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';\n\n";
//$head.="USE `$db`;\n\n";
$this->output($head);
$out = "";
/** FUNCTION & PROCEDURE */
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
$rows=$this->db->query("SHOW $routine STATUS WHERE Db='".$db."'")->result_array();
if($rows){
foreach($rows as $r){
$create=array_values($this->db->query("SHOW CREATE $routine ".$r['Name'])->row_array())[1];
$out.="DROP $routine IF EXISTS ".$r['Name'].";;\n".$create.";;\n\n";
}
}
}
/** EVENTS */
$rows=$this->db->query("SHOW EVENTS")->result_array();
if($rows){
foreach($rows as $r){
$create=array_values($this->db->query("SHOW CREATE EVENTS ".$r['Name'])->row_array())[1];
$out.="DROP EVENTS IF EXISTS ".$r['Name'].";;\n".$create.";;\n\n";
}
}
if($out){
$out="DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n";
$this->output($out);
}
/** */
$table_status=$this->db->query("SHOW TABLE STATUS")->result_array();
if($table_status){
$views = array();
foreach($table_status as $r){
$name=$r['Name'];
$table=in_array($name, (array) $config["tables"]);
$data=in_array($name, (array) $config["data"]);
if($r["Engine"] == "InnoDB") {
// ignore internal comment, unnecessary since MySQL 5.1.21
$r["Comment"] = preg_replace('~(?:(.+); )?InnoDB free: .*~', '\1', $r["Comment"]);
}
if(!isset($r["Engine"])) {
$r["Comment"] = "";
}
$this->dump_table($name, ($table ? $config["table_style"] : ""), ($r['Engine']===null));
if($r['Engine']===null){
$views[] = $name;
}elseif($data){
$this->dump_data($name, $config["data_style"]);
}
}
foreach ($views as $view) {
$this->dump_table($view, $config["table_style"], 1);
}
}
//pr($config);
}
}
//End of file