Ver Mensaje Individual
  #4 (permalink)  
Antiguo 07/12/2011, 11:37
elrey123
 
Fecha de Ingreso: febrero-2009
Mensajes: 61
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: Como Respaldar mi Base de Datos Mysql con PHP

hola igual implemente ese codigo de zital para hacer respaldo de mi base de datos te paso el codigo que utilize:

Código PHP:
Ver original
  1. <?php
  2. $boton = (isset($_POST['submit']) ? $_POST['submit'] : null);
  3.     function Connect($host,$user,$passwd)
  4.      {  
  5.       if(!($link=mysql_connect($host,$user,$passwd)))
  6.        {
  7.         echo "Error connecting to DDBB.";
  8.         exit();
  9.        }
  10.        return $link;
  11.      }
  12. $link=Connect('localhost','root','root');
  13. //
  14. if($boton)
  15.  {
  16.      $db=$_POST['db'];
  17.     $output=shell_exec("C:\wamp\bin\mysql\mysql5.5.8\bin\mysqldump.exe -u root -pmatrix ".$db); // ejemplo windows
  18.     //$output=shell_exec("/usr/bin/mysqldump -u root -proot ".$db); // ejemplo linux
  19.     //
  20.     if(trim($output)==NULL)
  21.      {
  22.          echo "Error creando el backup de la DB: ".$db;
  23.          exit();
  24.      }
  25.     header('Content-type: text/plain');
  26.     header('Content-Disposition: attachment; filename="'.$db.'.sql"');
  27.     echo $output;
  28.     exit();
  29.  }    
  30. $select="show databases";
  31. $select=mysql_query($select);
  32. ?>

Código HTML:
Ver original
  1. <title>RESPALDAR BASE DE DATOS</title></head>
  2. <link href="estilo/fondo.css" rel="stylesheet" type="text/css" />
  3. <link href="estilo/main.css" rel="stylesheet" type="text/css"/>
  4. <script src="estilo/validacion_campo_vacio.js" type="text/javascript"></script>
  5. <link href="estilo/Estilo_Error.css" rel="stylesheet" type="text/css" />
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  8. <title>Registrar Cliente</title>
  9. <style type="text/css">
  10. <!--
  11. .Estilo1 {color: #0066CC;
  12. font-family: Papyrus;
  13. }
  14. .Estilo2 {font-family: Papyrus}
  15. -->
  16. <DIV class="TabbedPanelsContentGroup">
  17.  <p>&nbsp;</p>
  18. <table width="70%" border="0" align="center">
  19.   <tr>
  20.     <th background="images/navi.jpg"><p class="Estilo1"><font size="+2"><p>&nbsp;</p><font color="blue">RESPALDO DE LA BASE DE DATOS</font></p><br/>
  21.      </th>
  22.   </tr>
  23. <p></p>
  24.  <table width="70%" border="0" align="center"  class="down">
  25.  
  26.     <tr>
  27.     <th>
  28. <center><h4>Selecciona la base de datos a respaldar de la siguiente lista de opciones.</h4></center>
  29. <p></p>
  30.  <form action="" method="post">
  31.  <table width="40%" border="0" align="center"  class="down">
  32.  
  33.     <tr>
  34.     <th>
  35.   <center><h4>Selecciona 1 base de datos:</h4></center>  
  36.   <center><select name="db">
  37.   <?php
  38.  while($row = mysql_fetch_row($select))
  39.   {
  40.       ?>
  41.        <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
  42.        <?php
  43.   }    
  44.  ?>
  45.   </select>
  46. <p></p>
  47.   <input type="submit" class="boot" name="submit" value="Crear Respaldo" /></center>
  48.  </th>
  49.     </tr>
  50.  </table>  
  51.  </form>
  52. </th>
  53.     </tr>
  54.  </table>
  55. <p></p>
  56. <center><a href="principal.php">Regresar</a></center>
  57. <p></p>
  58. </DIV>
  59. </body>
  60. </html>

solo tienes que modificar la parte de connect con msql que es localhost, el usuario y contraseña de mysql en mi caso es root y root. Despues hay que cambiar la ruta donde tienes instalado mysql. Espero que te sirva mi respueta saludos.