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년 전
감사합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7630 | 10년 전 | 633 | ||
| 7629 |
|
10년 전 | 2335 | |
| 7628 | 10년 전 | 768 | ||
| 7627 |
|
10년 전 | 991 | |
| 7626 |
|
10년 전 | 1754 | |
| 7625 | 10년 전 | 654 | ||
| 7624 | 10년 전 | 680 | ||
| 7623 |
|
10년 전 | 3000 | |
| 7622 | 10년 전 | 683 | ||
| 7621 |
leeleeleelee
|
10년 전 | 562 | |
| 7620 | 10년 전 | 524 | ||
| 7619 | 10년 전 | 448 | ||
| 7618 | 10년 전 | 992 | ||
| 7617 | 10년 전 | 707 | ||
| 7616 | 10년 전 | 604 | ||
| 7615 | 10년 전 | 698 | ||
| 7614 | 10년 전 | 1204 | ||
| 7613 |
|
10년 전 | 2043 | |
| 7612 | 10년 전 | 1113 | ||
| 7611 | 10년 전 | 1378 | ||
| 7610 |
|
10년 전 | 1871 | |
| 7609 |
|
10년 전 | 1286 | |
| 7608 |
mwdkim
|
10년 전 | 1091 | |
| 7607 |
|
10년 전 | 1018 | |
| 7606 |
mwdkim
|
10년 전 | 3895 | |
| 7605 | 10년 전 | 662 | ||
| 7604 | 10년 전 | 1000 | ||
| 7603 | 10년 전 | 1625 | ||
| 7602 |
|
10년 전 | 1040 | |
| 7601 |
AniNest
|
10년 전 | 2756 | |
| 7600 |
port443
|
10년 전 | 988 | |
| 7599 | 10년 전 | 914 | ||
| 7598 | 10년 전 | 988 | ||
| 7597 | 10년 전 | 4550 | ||
| 7596 |
SeungYeon
|
10년 전 | 864 | |
| 7595 |
untitled
|
10년 전 | 2385 | |
| 7594 |
프로그래머7
|
10년 전 | 1699 | |
| 7593 |
untitled
|
10년 전 | 2337 | |
| 7592 |
untitled
|
10년 전 | 1905 | |
| 7591 |
untitled
|
10년 전 | 2646 | |
| 7590 |
아리마2001
|
10년 전 | 817 | |
| 7589 | 10년 전 | 1075 | ||
| 7588 |
|
10년 전 | 2888 | |
| 7587 | 10년 전 | 1270 | ||
| 7586 | 10년 전 | 630 | ||
| 7585 | 10년 전 | 1651 | ||
| 7584 | 10년 전 | 1385 | ||
| 7583 |
leeleeleelee
|
10년 전 | 1117 | |
| 7582 |
|
10년 전 | 1068 | |
| 7581 | 10년 전 | 1302 | ||
| 7580 | 10년 전 | 941 | ||
| 7579 |
|
10년 전 | 578 | |
| 7578 | 10년 전 | 1385 | ||
| 7577 |
|
10년 전 | 1849 | |
| 7576 | 10년 전 | 1363 | ||
| 7575 |
멋진남자임
|
10년 전 | 1444 | |
| 7574 | 10년 전 | 2081 | ||
| 7573 | 10년 전 | 3212 | ||
| 7572 | 10년 전 | 744 | ||
| 7571 |
|
10년 전 | 770 | |
| 7570 |
|
10년 전 | 1283 | |
| 7569 | 10년 전 | 1517 | ||
| 7568 |
this1mg
|
10년 전 | 1020 | |
| 7567 |
|
10년 전 | 727 | |
| 7566 | 10년 전 | 888 | ||
| 7565 |
Angel하늘
|
10년 전 | 957 | |
| 7564 |
seoldi
|
10년 전 | 1194 | |
| 7563 |
|
10년 전 | 1344 | |
| 7562 |
멋진남자임
|
10년 전 | 2041 | |
| 7561 | 10년 전 | 679 | ||
| 7560 |
leeleeleelee
|
10년 전 | 875 | |
| 7559 | 10년 전 | 5006 | ||
| 7558 |
RinaP
|
10년 전 | 753 | |
| 7557 |
|
10년 전 | 1216 | |
| 7556 | 10년 전 | 1167 | ||
| 7555 |
hyohyojj1234
|
10년 전 | 1632 | |
| 7554 | 10년 전 | 1066 | ||
| 7553 |
senseme
|
10년 전 | 1320 | |
| 7552 |
ehdltdoit
|
10년 전 | 1413 | |
| 7551 |
|
10년 전 | 1790 | |
| 7550 |
leeleeleelee
|
10년 전 | 1554 | |
| 7549 | 10년 전 | 2391 | ||
| 7548 | 10년 전 | 1812 | ||
| 7547 |
멋진남자임
|
10년 전 | 1919 | |
| 7546 | 10년 전 | 964 | ||
| 7545 |
ILMare1003
|
10년 전 | 1252 | |
| 7544 |
|
10년 전 | 1209 | |
| 7543 | 10년 전 | 860 | ||
| 7542 | 10년 전 | 634 | ||
| 7541 |
울라라라우
|
10년 전 | 844 | |
| 7540 | 10년 전 | 1576 | ||
| 7539 | 10년 전 | 894 | ||
| 7538 |
|
10년 전 | 1806 | |
| 7537 | 10년 전 | 3580 | ||
| 7536 |
Gaumi
|
10년 전 | 1377 | |
| 7535 |
프로그램은어려워
|
10년 전 | 1241 | |
| 7534 |
senseme
|
10년 전 | 1190 | |
| 7533 | 10년 전 | 1164 | ||
| 7532 | 10년 전 | 830 | ||
| 7531 | 10년 전 | 2024 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기