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년 전
감사합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 6530 |
퍼블리셔강
|
12년 전 | 654 | |
| 6529 | 12년 전 | 1308 | ||
| 6528 | 12년 전 | 629 | ||
| 6527 | 12년 전 | 793 | ||
| 6526 | 12년 전 | 6581 | ||
| 6525 | 12년 전 | 552 | ||
| 6524 | 12년 전 | 843 | ||
| 6523 | 12년 전 | 498 | ||
| 6522 | 12년 전 | 541 | ||
| 6521 | 12년 전 | 802 | ||
| 6520 | 12년 전 | 745 | ||
| 6519 | 12년 전 | 1745 | ||
| 6518 |
가슴시린하늘
|
12년 전 | 1727 | |
| 6517 | 12년 전 | 1367 | ||
| 6516 | 12년 전 | 5229 | ||
| 6515 | 12년 전 | 1502 | ||
| 6514 | 12년 전 | 1603 | ||
| 6513 | 12년 전 | 958 | ||
| 6512 | 12년 전 | 1990 | ||
| 6511 | 12년 전 | 1377 | ||
| 6510 | 12년 전 | 3079 | ||
| 6509 |
프로프리랜서
|
12년 전 | 2553 | |
| 6508 |
프로프리랜서
|
12년 전 | 1900 | |
| 6507 |
프로프리랜서
|
12년 전 | 2377 | |
| 6506 |
프로프리랜서
|
12년 전 | 1859 | |
| 6505 |
프로프리랜서
|
12년 전 | 1635 | |
| 6504 | 12년 전 | 1047 | ||
| 6503 | 12년 전 | 1134 | ||
| 6502 |
프로프리랜서
|
12년 전 | 5560 | |
| 6501 |
프로프리랜서
|
12년 전 | 2609 | |
| 6500 |
프로프리랜서
|
12년 전 | 3092 | |
| 6499 |
프로프리랜서
|
12년 전 | 1752 | |
| 6498 |
프로프리랜서
|
12년 전 | 1467 | |
| 6497 | 12년 전 | 816 | ||
| 6496 |
yunkiri486
|
12년 전 | 1816 | |
| 6495 | 12년 전 | 924 | ||
| 6494 | 12년 전 | 1495 | ||
| 6493 | 12년 전 | 2766 | ||
| 6492 |
오늘도망했다
|
12년 전 | 2339 | |
| 6491 |
오늘도망했다
|
12년 전 | 1678 | |
| 6490 |
오늘도망했다
|
12년 전 | 6661 | |
| 6489 |
오늘도망했다
|
12년 전 | 2501 | |
| 6488 |
홈피119
|
12년 전 | 704 | |
| 6487 | 12년 전 | 688 | ||
| 6486 | 12년 전 | 1412 | ||
| 6485 | 12년 전 | 2055 | ||
| 6484 | 12년 전 | 905 | ||
| 6483 | 12년 전 | 724 | ||
| 6482 | 12년 전 | 1347 | ||
| 6481 | 12년 전 | 1475 | ||
| 6480 |
Header
|
12년 전 | 692 | |
| 6479 |
|
12년 전 | 1131 | |
| 6478 |
개초보제이
|
12년 전 | 1397 | |
| 6477 | 12년 전 | 805 | ||
| 6476 | 12년 전 | 1078 | ||
| 6475 | 12년 전 | 3690 | ||
| 6474 | 12년 전 | 1433 | ||
| 6473 | 12년 전 | 963 | ||
| 6472 | 12년 전 | 859 | ||
| 6471 |
AMDbest
|
12년 전 | 1209 | |
| 6470 |
jinmuk
|
12년 전 | 1450 | |
| 6469 |
jinmuk
|
12년 전 | 4252 | |
| 6468 |
jinmuk
|
12년 전 | 5584 | |
| 6467 | 12년 전 | 708 | ||
| 6466 |
jinmuk
|
12년 전 | 2285 | |
| 6465 |
jinmuk
|
12년 전 | 6742 | |
| 6464 |
jinmuk
|
12년 전 | 2411 | |
| 6463 |
jinmuk
|
12년 전 | 9338 | |
| 6462 |
희망과열정
|
12년 전 | 543 | |
| 6461 |
Header
|
12년 전 | 730 | |
| 6460 |
희망과열정
|
12년 전 | 1364 | |
| 6459 |
프리랜서개발자
|
12년 전 | 1679 | |
| 6458 | 12년 전 | 1343 | ||
| 6457 |
jinmuk
|
12년 전 | 1953 | |
| 6456 |
jinmuk
|
12년 전 | 2353 | |
| 6455 |
jinmuk
|
12년 전 | 3213 | |
| 6454 |
jinmuk
|
12년 전 | 2180 | |
| 6453 |
jinmuk
|
12년 전 | 2364 | |
| 6452 |
jinmuk
|
12년 전 | 2320 | |
| 6451 |
jinmuk
|
12년 전 | 1615 | |
| 6450 |
jinmuk
|
12년 전 | 1404 | |
| 6449 |
jinmuk
|
12년 전 | 1050 | |
| 6448 |
jinmuk
|
12년 전 | 1252 | |
| 6447 |
jinmuk
|
12년 전 | 2019 | |
| 6446 |
jinmuk
|
12년 전 | 1575 | |
| 6445 |
jinmuk
|
12년 전 | 1267 | |
| 6444 |
jinmuk
|
12년 전 | 2318 | |
| 6443 |
jinmuk
|
12년 전 | 2049 | |
| 6442 |
jinmuk
|
12년 전 | 1896 | |
| 6441 |
jinmuk
|
12년 전 | 1627 | |
| 6440 |
jinmuk
|
12년 전 | 2325 | |
| 6439 |
jinmuk
|
12년 전 | 1141 | |
| 6438 |
wndProc
|
12년 전 | 790 | |
| 6437 | 12년 전 | 411 | ||
| 6436 |
senseme
|
12년 전 | 554 | |
| 6435 | 12년 전 | 1051 | ||
| 6434 | 12년 전 | 2486 | ||
| 6433 | 12년 전 | 2493 | ||
| 6432 | 12년 전 | 1568 | ||
| 6431 |
밥먹고합시다
|
12년 전 | 1195 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기