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년 전
감사합니다
게시판 목록
팁게시판
디자인과 관련된 유용한 정보를 공유하세요.
질문은 상단의 QA에서 해주시기 바랍니다.
질문은 상단의 QA에서 해주시기 바랍니다.
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5102 | 12년 전 | 3467 | ||
| 5101 | 12년 전 | 2516 | ||
| 5100 |
senseme
|
12년 전 | 1837 | |
| 5099 |
senseme
|
12년 전 | 1533 | |
| 5098 |
senseme
|
12년 전 | 1520 | |
| 5097 |
senseme
|
12년 전 | 1279 | |
| 5096 |
senseme
|
12년 전 | 1674 | |
| 5095 |
senseme
|
12년 전 | 1355 | |
| 5094 |
senseme
|
12년 전 | 2418 | |
| 5093 |
senseme
|
12년 전 | 1614 | |
| 5092 |
senseme
|
12년 전 | 2223 | |
| 5091 |
senseme
|
12년 전 | 2110 | |
| 5090 |
senseme
|
12년 전 | 1748 | |
| 5089 |
senseme
|
12년 전 | 4528 | |
| 5088 |
senseme
|
12년 전 | 2667 | |
| 5087 |
senseme
|
12년 전 | 2822 | |
| 5086 |
senseme
|
12년 전 | 1232 | |
| 5085 |
senseme
|
12년 전 | 8506 | |
| 5084 |
senseme
|
12년 전 | 3317 | |
| 5083 |
senseme
|
12년 전 | 2660 | |
| 5082 |
senseme
|
12년 전 | 5308 | |
| 5081 |
senseme
|
12년 전 | 3381 | |
| 5080 | 12년 전 | 13281 | ||
| 5079 | 12년 전 | 3888 | ||
| 5078 | 12년 전 | 1457 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기