Tutorials Infos - Anleitungen - Hilfe - Dreamcodes
 

Sql Backup

Mit diesem Schnipsel ist es möglich eine MySQL Tabelle in einer Datei runter zu laden

Script:

<?php

$user
= "username";
$pw = "password";
$host = "localhost";
$database = "datenbank";
$table = "cms_test"; // zu sichernde Tabelle

$conn_id = @mysql_connect($host,$user,$pw);
mysql_select_db($database,$conn_id);

$result = mysql_query("SELECT * FROM $table");
$file = '';
while(
$row = mysql_fetch_row($result)) {
  
$ins = implode($row,"','");
  
$ins = str_replace("n",'n',$ins);
  
$ins = str_replace("r",'r',$ins);
  
$ins = str_replace("t",'t',$ins);
  
$file .= 'INSERT INTO `'.$table.'` VALUES ('."'".$ins."');rn";
}

header("Pragma: cache");
header("Content-Type: text/sql");
header("Content-Disposition: attachment; filename=".urlencode($table).".sql");
echo
$file;

?>

 
ID: 236
eingestellt am: 15.02.2004
Autor: Ilch
Status zum lesen: Gast
gelesen: 7083
Webseite: www.dreamcodes.com
[Drucken]