Tengo un script para respaldar mi base de datos pero ahora no se como hacer que con otro me permita importar este archivo. Este es el script que tengo:
Código PHP:
<?php
error_reporting(E_ALL);
define("DB_USER", 'root');
define("DB_PASSWORD", '12345');
define("DB_NAME", 'isste');
define("DB_HOST", 'localhost');
define("OUTPUT_DIR", 'C:\Respaldos');
define("TABLES", '*');
$backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$status = $backupDatabase->backupTables(TABLES, OUTPUT_DIR) ? 'Exitoso' : 'KO';
echo "<br /><br /><br />Respaldo Total: ".$status;
class Backup_Database {
var $host = '';
var $username = '';
var $passwd = '';
var $dbName = '';
var $charset = '';
function Backup_Database($host, $username, $passwd, $dbName, $charset = 'utf8')
{
$this->host = $host;
$this->username = $username;
$this->passwd = $passwd;
$this->dbName = $dbName;
$this->charset = $charset;
$this->initializeDatabase();
}
protected function initializeDatabase()
{
$conn = mysql_connect($this->host, $this->username, $this->passwd);
mysql_select_db($this->dbName, $conn);
if (! mysql_set_charset ($this->charset, $conn))
{
mysql_query('SET NAMES '.$this->charset);
}
}
public function backupTables($tables = '*', $outputDir = '.')
{
try
{
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
$sql = 'CREATE DATABASE IF NOT EXISTS '.$this->dbName.";\n\n";
$sql .= 'USE '.$this->dbName.";\n\n";
/**
* Iterate tables
*/
foreach($tables as $table)
{
echo "<br>Respaldo de tabla: ".$table;
$result = mysql_query('SELECT * FROM '.$table);
$numFields = mysql_num_fields($result);
$sql .= 'DROP TABLE IF EXISTS '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$sql.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $numFields; $i++)
{
while($row = mysql_fetch_row($result))
{
$sql .= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$numFields; $j++)
{
$row[$j] = addslashes($row[$j]);
@$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j]))
{
$sql .= '"'.$row[$j].'"' ;
}
else
{
$sql.= '""';
}
if ($j < ($numFields-1))
{
$sql .= ',';
}
}
$sql.= ");\n";
}
}
$sql.="\n\n\n";
echo " ...Guardada" . "<br />";
}
}
catch (Exception $e)
{
var_dump($e->getMessage());
return false;
}
return $this->saveFile($sql, $outputDir);
}
/**
* Save SQL to file
* @param string $sql
*/
protected function saveFile(&$sql, $outputDir = '.')
{
if (!$sql) return false;
try
{
$handle = fopen($outputDir.'/Respaldo_ISSSTE-'.date("d-m-Y-H-i", time()-21600).'.sql','w+');
fwrite($handle, $sql);
fclose($handle);
}
catch (Exception $e)
{
var_dump($e->getMessage());
return false;
}
return true;
}
}
?>
Alguien me podria facilitar alguno que realize la restauracion de este archivo.Se lo agredeceria muchisimo.