Código PHP:
<?php
// Conexión con la Base de Datos.
$db_server = "127.0.0.1";
$db_name = "nombre_DDBB";
$db_username = "nombre_usuario";
$db_password = "contrasena";
$filename = date("Y-m-d_H-i-s");
//-------------
//Funciones
error_reporting( E_ALL & ~E_NOTICE );
function fetch_table_dump_sql($table, $fp = 0) {
$rows_en_tabla = 0;
$tabledump = "--\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "-- Table structure for table `$table`\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "--\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = query_first("SHOW CREATE TABLE $table");
strip_backticks($tabledump['Create Table']);
$tabledump = "DROP TABLE IF EXISTS $table;\n" . $tabledump['Create Table'] . ";\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "--\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "-- Dumping data for table `$table`\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "--\n\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$tabledump = "LOCK TABLES $table WRITE;\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$rows = query("SELECT * FROM $table");
$numfields=mysql_num_fields($rows);
while ($row = fetch_array($rows, DBARRAY_NUM)) {
$tabledump = "INSERT INTO $table VALUES(";
$fieldcounter = -1;
$firstfield = 1;
// campos
while (++$fieldcounter < $numfields) {
if( !$firstfield) {
$tabledump .= ', ';
}else {
$firstfield = 0;
}
if( !isset($row["$fieldcounter"])) {
$tabledump .= 'NULL';
}else {
$tabledump .= "'" . mysql_escape_string($row["$fieldcounter"]) . "'";
}
}
$tabledump .= ");\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
$rows_en_tabla++;
}
free_result($rows);
$tabledump = "UNLOCK TABLES;\n";
if( !$hay_Zlib )
fwrite($fp, $tabledump);
else
gzwrite($fp, $tabledump);
return $rows_en_tabla;
}
function strip_backticks(&$text) {
return $text;
}
function fetch_array($query_id=-1) {
if( $query_id!=-1) {
$query_id=$query_id;
}
$record = mysql_fetch_array($query_id);
return $record;
}
function problemas($msg) {
$errdesc = mysql_error();
$errno = mysql_errno();
$message = "<br>";
$message .= "- Ha habido un problema accediendo a la Base de Datos<br>";
$message .= "- Error $appname: $msg<br>";
$message .= "- Error mysql: $errdesc<br>";
$message .= "- Error número mysql: $errno<br>";
$message .= "- Script: ".getenv("REQUEST_URI")."<br>";
$message .= "- Referer: ".getenv("HTTP_REFERER")."<br>";
echo( "</strong><br><br><hr><center><small>" );
setlocale( LC_TIME,"spanish" );
echo strftime( "%A %d %B %Y - %H:%M:%S", time() );
echo( "</small></center>" );
echo( "</BODY>" );
echo( "</HTML>" );
die("");
} ?>
Sigo en el siguite post que no me deja ponerlo todo en uno.. va junto en 1 solo.