phpmyadmin 들어가지않고
php로 간단하게 sql 백업 받는 소스입니다.
backup_tables('localhost','ID','PW','DB'); 의 코드를 본인의 계정에 맞게
수정하셔서 쓰시면 됩니다.
코드를 실행하면 20121111.sql 처럼 파일이 생성됩니다.
[code]
<?php
backup_tables('localhost','ID','PW','DB');
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
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);
}
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
[/code]
댓글 5개
넓은마인드
12년 전
좋네요
유용하게 쓰겠습니다~
유용하게 쓰겠습니다~
12년 전
엌 편하네요 감사합니다!
천재조상훈
12년 전
감사합니다.
ppogul
12년 전
잘 쓸께요^^
12년 전
감사합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 360 | ||
| 7929 | 9년 전 | 252 | ||
| 7928 | 9년 전 | 360 | ||
| 7927 | 9년 전 | 287 | ||
| 7926 | 9년 전 | 637 | ||
| 7925 | 9년 전 | 305 | ||
| 7924 | 9년 전 | 269 | ||
| 7923 | 9년 전 | 316 | ||
| 7922 | 9년 전 | 331 | ||
| 7921 | 9년 전 | 368 | ||
| 7920 | 9년 전 | 290 | ||
| 7919 | 9년 전 | 303 | ||
| 7918 | 9년 전 | 471 | ||
| 7917 | 9년 전 | 310 | ||
| 7916 | 9년 전 | 374 | ||
| 7915 | 9년 전 | 356 | ||
| 7914 | 9년 전 | 378 | ||
| 7913 | 9년 전 | 494 | ||
| 7912 | 9년 전 | 369 | ||
| 7911 | 9년 전 | 325 | ||
| 7910 | 9년 전 | 350 | ||
| 7909 | 9년 전 | 460 | ||
| 7908 | 9년 전 | 363 | ||
| 7907 | 9년 전 | 311 | ||
| 7906 | 9년 전 | 326 | ||
| 7905 | 9년 전 | 323 | ||
| 7904 | 9년 전 | 284 | ||
| 7903 | 9년 전 | 283 | ||
| 7902 | 9년 전 | 503 | ||
| 7901 |
|
9년 전 | 712 | |
| 7900 | 9년 전 | 535 | ||
| 7899 | 9년 전 | 339 | ||
| 7898 | 9년 전 | 334 | ||
| 7897 | 9년 전 | 293 | ||
| 7896 | 9년 전 | 311 | ||
| 7895 | 9년 전 | 419 | ||
| 7894 | 9년 전 | 343 | ||
| 7893 | 9년 전 | 269 | ||
| 7892 | 9년 전 | 310 | ||
| 7891 | 9년 전 | 699 | ||
| 7890 | 9년 전 | 1164 | ||
| 7889 | 9년 전 | 726 | ||
| 7888 |
limsy1987
|
9년 전 | 516 | |
| 7887 | 9년 전 | 498 | ||
| 7886 | 9년 전 | 375 | ||
| 7885 | 9년 전 | 354 | ||
| 7884 | 9년 전 | 360 | ||
| 7883 | 9년 전 | 337 | ||
| 7882 | 9년 전 | 351 | ||
| 7881 | 9년 전 | 373 | ||
| 7880 | 9년 전 | 505 | ||
| 7879 | 9년 전 | 408 | ||
| 7878 | 9년 전 | 1142 | ||
| 7877 | 9년 전 | 701 | ||
| 7876 | 9년 전 | 428 | ||
| 7875 | 9년 전 | 498 | ||
| 7874 |
|
9년 전 | 770 | |
| 7873 | 9년 전 | 475 | ||
| 7872 | 9년 전 | 601 | ||
| 7871 | 9년 전 | 439 | ||
| 7870 | 9년 전 | 559 | ||
| 7869 | 9년 전 | 383 | ||
| 7868 | 9년 전 | 367 | ||
| 7867 | 9년 전 | 371 | ||
| 7866 | 9년 전 | 428 | ||
| 7865 | 9년 전 | 390 | ||
| 7864 | 9년 전 | 451 | ||
| 7863 | 9년 전 | 442 | ||
| 7862 | 9년 전 | 419 | ||
| 7861 | 9년 전 | 583 | ||
| 7860 | 9년 전 | 589 | ||
| 7859 | 9년 전 | 360 | ||
| 7858 | 9년 전 | 665 | ||
| 7857 | 9년 전 | 1017 | ||
| 7856 | 9년 전 | 470 | ||
| 7855 | 9년 전 | 691 | ||
| 7854 | 9년 전 | 692 | ||
| 7853 | 9년 전 | 521 | ||
| 7852 | 9년 전 | 465 | ||
| 7851 | 9년 전 | 437 | ||
| 7850 | 9년 전 | 534 | ||
| 7849 | 9년 전 | 308 | ||
| 7848 | 9년 전 | 346 | ||
| 7847 | 9년 전 | 573 | ||
| 7846 | 9년 전 | 399 | ||
| 7845 | 9년 전 | 364 | ||
| 7844 | 9년 전 | 356 | ||
| 7843 | 9년 전 | 365 | ||
| 7842 | 9년 전 | 361 | ||
| 7841 | 9년 전 | 348 | ||
| 7840 | 9년 전 | 352 | ||
| 7839 | 9년 전 | 385 | ||
| 7838 | 9년 전 | 471 | ||
| 7837 | 9년 전 | 313 | ||
| 7836 | 9년 전 | 354 | ||
| 7835 | 9년 전 | 431 | ||
| 7834 |
|
9년 전 | 1166 | |
| 7833 | 9년 전 | 372 | ||
| 7832 | 9년 전 | 358 | ||
| 7831 | 9년 전 | 492 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기