Autor Zpráva
blast3r
Profil
Potreboval by som phpscript, ktory mi Defragmentuje tabulky, a vytvori zalohy(ten script budem vykonavat cez CRON). Nieco ako je v PHPMYADMINe.
Anonymní
Profil *
No, tak bych to vytahl z toho:) KER
Ivorius
Profil
Nechápu co je tohle za odpověď. Zase někdo spamuje
blast3r
Profil
To Anonymní:
Lenze zdrojovy kod phpmyadminu ma 6.53MB, a vtom sa mi nechce hrabat :(

To Admin:
Zmazte tu reklamu od anonym

To ostatni:
Vazne nic takeho nepoznate??
Vsak ten phpmyadmin to musi nejako robit!!
Hugo
Profil
blast3r

No ja to delam tak, ze selectem vytahnu data a pak je pomoci sprintf vlozim do sady sql prikazu, ktere ulozim do souboru. Jinak muzes taky pomoci crona spoustet mysqldump, ten ti to vyexportuje sam (viz man mysqldump).
blast3r
Profil
Hugo
Co je to mysqldump ??? Kde to mozem stiahnut??
Hugo
Profil
podivej se do dokumentace (man mysqldump), prip. googluj. Stahovat to nemusis, je soucasti mysql.
blast3r
Profil
Hugo:
Lenze ja hostujem na ic.cz a nemam uplny pristup do db, jediny pristup mam cez phpmyadmin :(
Hugo
Profil
blast3r

Tak to udelej pres php. Vyber vsechny data z tabulky a pak je uloz do souboru jako sql prikazy. Ten soubor potom muzes primo vlozit do phpmyadmina.
blast3r
Profil
No, tak som sa opytal na intervale a tu je pre ostatnych vysledok:

<?php
$config["dbserver"] = "localhost";
$config["dbuser"] = "root";
$config["dbpass"] = "";
$config["dbname"] = "hyge";
$config["table_names"] = "*"; // all tables
// $config["table_names"] = "stats|users"; // from tables: "stats" and "users"
$config["filename"] = "backup.sql";

$dbhost = $config["dbserver"];
$dbuser = $config["dbuser"];
$dbpass = $config["dbpass"];
$dbname = $config["dbname"];
$table_names = $config["table_names"];
$filename = $config["filename"];


function get_def($dbname, $table) {
global $conn;
$def = "";
$def .= "DROP TABLE IF EXISTS `$table`;\n";
$dotaz = "SHOW CREATE TABLE `$table`";
$result = mysql_db_query($dbname, $dotaz, $conn) or die("Query failed : ".$dotaz);
$def .= mysql_result($result,0, "Create Table");
$def .= ";";
return $def;
}

function get_content($dbname, $table) {
global $conn;
$content="";
$dotaz = "SELECT * FROM `$table`";
$result = mysql_db_query($dbname, $dotaz, $conn) or die("Query failed : ".$dotaz);
while($row = mysql_fetch_row($result)) {
$insert = "INSERT INTO `$table` VALUES (";
for($j=0; $j<mysql_num_fields($result); $j++) {
if(!isset($row[$j])) {
$insert .= "NULL,";
} else if($row[$j] == "") {
$insert .= "'',";
} else {
$insert .= "'".ereg_replace("\r\n","\\r\\n",addslashes($row[$j]))."',";
}
}
$insert = ereg_replace(",$","",$insert); /* remove at end of query ', ' */
$insert .= ");\n";
$content .= $insert;
}
return $content;
}


$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if ($conn==false) die("password / user or database name wrong");


if ($table_names == "*" )
{
$tables = mysql_list_tables($dbname,$conn);
$num_tables = @mysql_num_rows($tables);
$i = 0;
while($i < $num_tables) {
$table = mysql_tablename($tables, $i);
$newfile .= get_def($dbname,$table);
$newfile .= "\n\n";
$newfile .= get_content($dbname,$table);
$newfile .= "\n\n";
$i++;
}
} else {
$tables = explode("|",$table_names);
$num_tables = count($tables);
$i = 0;
while($i < $num_tables) {
$newfile .= get_def($dbname,$tables[$i]);
$newfile .= "\n\n";
$newfile .= get_content($dbname,$tables[$i]);
$newfile .= "\n\n";
$i++;
}

}
/*
// save to file
$fp = fopen ("backup.sql","w");
fwrite ($fp,$newfile);
fclose ($fp);
*/


header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Content-Transfer-Encoding: none');
if (strpos ($_SERVER["HTTP_USER_AGENT"], "MSIE") === false) {
header('Content-Type: application/octet-stream; name="' . $filename . '"'); //This should work for the rest
} else {
header('Content-Type: application/octetstream; name="' . $filename . '"'); //This should work for IE & Opera
}
header('Content-Disposition: inline; filename="' . $filename . '"');


echo $newfile;

mysql_close($conn);


?>
Toto téma je uzamčeno. Odpověď nelze zaslat.

0