Ver Mensaje Individual
  #3 (permalink)  
Antiguo 20/11/2007, 05:44
Avatar de ZiTAL
ZiTAL
 
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 20 años, 1 mes
Puntos: 62
Re: como respaldar mi base de datos con php

Bueno como estaba un poco aburrido te ahorro un poco de codigo:
Código PHP:
<?php
    
function Connect($host,$user,$passwd)
     {  
      if(!(
$link=mysql_connect($host,$user,$passwd)))
       {
        echo 
"Error connecting to DDBB.";
        exit();
       }
       return 
$link;
     }
$link=Connect('localhost','root','root');
//
if($_POST['submit'])
 { 
     
$db=$_POST['db'];
    
$output=shell_exec("d:\apps\mysql-5.0.45-win32\bin\mysqldump.exe -u root -proot ".$db); // ejemplo windows
    //$output=shell_exec("/usr/bin/mysqldump -u root -proot ".$db); // ejemplo linux
    //
    
if(trim($output)==NULL)
     {
         echo 
"Error creando el backup de la DB: ".$db;
         exit();
     }
    
header('Content-type: text/plain');
    
header('Content-Disposition: attachment; filename="'.$db.'.sql"');
    echo 
$output;
    exit();
 }    
$select="show databases";
$select=mysql_query($select); 
?>
<html>
<head>
</head>
<body>
 <form action="" method="post">  
  <select name="db">
  <?php
  
while($row mysql_fetch_row($select))
   {
       
?>
       <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
       <?php
   
}    
  
?>
  </select>
  <input type="submit" name="submit" value="Crear backup" />  
 </form>
</body>
</html>
tienes que cambiar las rutas correspondientes al ejecutable mysqldump y logicamente el usuario y password para conectarte a mysql

;)
__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan