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개
넓은마인드
13년 전
좋네요
유용하게 쓰겠습니다~
유용하게 쓰겠습니다~
13년 전
엌 편하네요 감사합니다!
천재조상훈
13년 전
감사합니다.
ppogul
12년 전
잘 쓸께요^^
12년 전
감사합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6030 | 12년 전 | 2833 | ||
| 6029 | 12년 전 | 2854 | ||
| 6028 | 12년 전 | 1478 | ||
| 6027 | 12년 전 | 899 | ||
| 6026 |
kiplayer
|
12년 전 | 813 | |
| 6025 | 12년 전 | 610 | ||
| 6024 | 12년 전 | 2828 | ||
| 6023 | 12년 전 | 2959 | ||
| 6022 |
|
12년 전 | 2114 | |
| 6021 |
Holyreign
|
12년 전 | 1346 | |
| 6020 | 12년 전 | 793 | ||
| 6019 | 12년 전 | 2864 | ||
| 6018 | 12년 전 | 3200 | ||
| 6017 | 12년 전 | 1246 | ||
| 6016 |
kiplayer
|
12년 전 | 10587 | |
| 6015 |
itlang
|
12년 전 | 1428 | |
| 6014 | 12년 전 | 434 | ||
| 6013 |
senseme
|
12년 전 | 1368 | |
| 6012 | 12년 전 | 3117 | ||
| 6011 | 12년 전 | 7134 | ||
| 6010 | 12년 전 | 8969 | ||
| 6009 | 12년 전 | 2877 | ||
| 6008 | 12년 전 | 2999 | ||
| 6007 | 12년 전 | 6680 | ||
| 6006 | 12년 전 | 10521 | ||
| 6005 | 12년 전 | 4057 | ||
| 6004 |
|
12년 전 | 589 | |
| 6003 | 12년 전 | 893 | ||
| 6002 | 12년 전 | 2355 | ||
| 6001 | 12년 전 | 692 | ||
| 6000 |
kiplayer
|
12년 전 | 3745 | |
| 5999 | 12년 전 | 443 | ||
| 5998 |
|
12년 전 | 2950 | |
| 5997 |
|
12년 전 | 3446 | |
| 5996 | 12년 전 | 2105 | ||
| 5995 |
kiplayer
|
12년 전 | 2179 | |
| 5994 |
|
12년 전 | 3276 | |
| 5993 |
windowhan
|
12년 전 | 684 | |
| 5992 | 12년 전 | 2907 | ||
| 5991 | 12년 전 | 5241 | ||
| 5990 | 12년 전 | 1645 | ||
| 5989 |
AMDbest
|
12년 전 | 1357 | |
| 5988 | 12년 전 | 1223 | ||
| 5987 |
kiplayer
|
12년 전 | 1141 | |
| 5986 |
한번잘해보자
|
12년 전 | 931 | |
| 5985 |
kiplayer
|
12년 전 | 3144 | |
| 5984 |
dsv421
|
12년 전 | 811 | |
| 5983 |
dsv421
|
12년 전 | 1512 | |
| 5982 |
dsv421
|
12년 전 | 5843 | |
| 5981 | 12년 전 | 3221 | ||
| 5980 |
MFBob
|
12년 전 | 2629 | |
| 5979 | 12년 전 | 3105 | ||
| 5978 |
AMDbest
|
12년 전 | 1465 | |
| 5977 | 12년 전 | 796 | ||
| 5976 | 12년 전 | 1214 | ||
| 5975 | 12년 전 | 1284 | ||
| 5974 | 12년 전 | 616 | ||
| 5973 |
kiplayer
|
12년 전 | 3559 | |
| 5972 |
kiplayer
|
12년 전 | 3983 | |
| 5971 |
kiplayer
|
12년 전 | 2306 | |
| 5970 |
kiplayer
|
12년 전 | 8299 | |
| 5969 |
kiplayer
|
12년 전 | 953 | |
| 5968 | 12년 전 | 8749 | ||
| 5967 |
|
12년 전 | 16908 | |
| 5966 | 12년 전 | 1234 | ||
| 5965 | 12년 전 | 716 | ||
| 5964 | 12년 전 | 6259 | ||
| 5963 | 12년 전 | 710 | ||
| 5962 | 12년 전 | 891 | ||
| 5961 | 12년 전 | 643 | ||
| 5960 | 12년 전 | 787 | ||
| 5959 |
|
12년 전 | 1125 | |
| 5958 | 12년 전 | 987 | ||
| 5957 |
웹디자인되고파
|
12년 전 | 1094 | |
| 5956 | 12년 전 | 3663 | ||
| 5955 | 12년 전 | 2143 | ||
| 5954 | 12년 전 | 4403 | ||
| 5953 | 12년 전 | 3093 | ||
| 5952 | 12년 전 | 4270 | ||
| 5951 | 12년 전 | 2085 | ||
| 5950 | 12년 전 | 1284 | ||
| 5949 | 12년 전 | 940 | ||
| 5948 | 12년 전 | 2086 | ||
| 5947 | 12년 전 | 5009 | ||
| 5946 |
dsv421
|
12년 전 | 1277 | |
| 5945 |
dsv421
|
12년 전 | 4125 | |
| 5944 |
dsv421
|
12년 전 | 5648 | |
| 5943 | 12년 전 | 1294 | ||
| 5942 | 12년 전 | 2545 | ||
| 5941 |
프로프리랜서
|
12년 전 | 1648 | |
| 5940 |
atria
|
12년 전 | 621 | |
| 5939 | 12년 전 | 2348 | ||
| 5938 | 12년 전 | 2090 | ||
| 5937 |
프로프리랜서
|
12년 전 | 780 | |
| 5936 |
프로프리랜서
|
12년 전 | 718 | |
| 5935 |
프로프리랜서
|
12년 전 | 3223 | |
| 5934 |
프로프리랜서
|
12년 전 | 1648 | |
| 5933 |
AMDbest
|
12년 전 | 663 | |
| 5932 |
AMDbest
|
12년 전 | 507 | |
| 5931 | 12년 전 | 8145 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기