note 102114 added to function.mysql-field-flags
| From: | gechillter at osu1 dot php dot net | Date: | Thu, 27 Jan 2011 15:18:40 +0000 |
| Subject: | note 102114 added to function.mysql-field-flags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176393@lists.php.net to get a copy of this message | ||
This function returns a phpmyadmin mysql dump.
Thanks to play & boma!
<?PHP
/**
/* backups either all tables or just one table from a database
/* Returns a phpmyadmin look alike mysql export
/**/
function mysql_backup($databaseName,$tableName=''){
$str_backup='';
//Get Auto_increment Values
$tab_status = mysql_query("SHOW TABLE STATUS");
while($all = mysql_fetch_assoc($tab_status)):
$tbl_stat[$all[Name]] = $all[Auto_increment];
endwhile;
$tables=array();
if($tableName==''){
//all tables in database
$tableinfos = mysql_list_tables($databaseName);
while($tab = mysql_fetch_row($tableinfos)){
array_push($tables,$tab[0]);
}
}else{
//just one table
array_push($tables,$tableName);
}
foreach ($tables as $table){
$str_backup .= "--\n-- table structure for
$table\n--\n\nCREATE TABLE IF NOT
EXISTS $table ( ";
$res = mysql_query("SHOW CREATE TABLE $table");
while($all = mysql_fetch_assoc($res)):
$str = str_replace("CREATE TABLE $table (", "",
$all['Create Table']);
$str = str_replace(",", ", ", $str);
$str = str_replace(") ) TYPE=MyISAM ", ")\n ) TYPE=MyISAM ",
$str);
$str_backup .= $str." AUTO_INCREMENT=".$tbl_stat[$table].";\n\n";
endwhile;
$str_backup .= "--\n-- data for table $table\n--\n\n";
$data = mysql_query("SELECT * FROM $table");
$nbc = mysql_num_fields($data);
while ($dt = mysql_fetch_array($data)){
$str_backup .= "INSERT INTO $table VALUES(";
for ($i=0; $i<$nbc; $i++){
if($i>0){$str_backup .= ", ";}
if(!isset($dt[$i])){
$str_backup .= "NULL";
}else{
$str_backup .= "'" . mysql_real_escape_string($dt[$i]). "'";
}
}
$str_backup .= ");\n";
}
$str_backup .= "\n-- --------------------------------------------------------\n\n";
}
return $str_backup;
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 91.33.220.254
----
Manual Page -- http://www.php.net/manual/en/function.mysql-field-flags.php
Edit -- https://master.php.net/note/edit/102114
Del: integrated -- https://master.php.net/note/delete/102114/integrated
Del: useless -- https://master.php.net/note/delete/102114/useless
Del: bad code -- https://master.php.net/note/delete/102114/bad+code
Del: spam -- https://master.php.net/note/delete/102114/spam
Del: non-english -- https://master.php.net/note/delete/102114/non-english
Del: in docs -- https://master.php.net/note/delete/102114/in+docs
Del: other reasons-- https://master.php.net/note/delete/102114
Reject -- https://master.php.net/note/reject/102114
Search -- https://master.php.net/manage/user-notes.php