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년 전
감사합니다
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 430 | 19년 전 | 4130 | ||
| 429 | 19년 전 | 3324 | ||
| 428 | 19년 전 | 4144 | ||
| 427 | 19년 전 | 3493 | ||
| 426 | 19년 전 | 3119 | ||
| 425 | 19년 전 | 3430 | ||
| 424 | 19년 전 | 2452 | ||
| 423 | 19년 전 | 2881 | ||
| 422 | 19년 전 | 2373 | ||
| 421 | 19년 전 | 3723 | ||
| 420 | 19년 전 | 4755 | ||
| 419 | 19년 전 | 3831 | ||
| 418 |
|
19년 전 | 1767 | |
| 417 | 19년 전 | 2767 | ||
| 416 | 19년 전 | 2411 | ||
| 415 | 19년 전 | 2614 | ||
| 414 | 19년 전 | 4430 | ||
| 413 |
|
19년 전 | 2624 | |
| 412 | 19년 전 | 3067 | ||
| 411 |
|
19년 전 | 3003 | |
| 410 |
|
19년 전 | 3710 | |
| 409 |
|
19년 전 | 3652 | |
| 408 |
|
19년 전 | 1873 | |
| 407 | 19년 전 | 2245 | ||
| 406 | 19년 전 | 2811 | ||
| 405 | 19년 전 | 2477 | ||
| 404 | 19년 전 | 4323 | ||
| 403 | 19년 전 | 3315 | ||
| 402 |
NeoGenesis
|
19년 전 | 4111 | |
| 401 | 19년 전 | 2621 | ||
| 400 |
|
19년 전 | 2527 | |
| 399 | 19년 전 | 2979 | ||
| 398 | 19년 전 | 2512 | ||
| 397 | 19년 전 | 2808 | ||
| 396 | 19년 전 | 2510 | ||
| 395 | 19년 전 | 3219 | ||
| 394 | 19년 전 | 1761 | ||
| 393 | 19년 전 | 3013 | ||
| 392 | 19년 전 | 2291 | ||
| 391 | 19년 전 | 2192 | ||
| 390 | 19년 전 | 2303 | ||
| 389 | 19년 전 | 2666 | ||
| 388 | 19년 전 | 2211 | ||
| 387 | 19년 전 | 4495 | ||
| 386 |
|
19년 전 | 2703 | |
| 385 |
|
19년 전 | 2511 | |
| 384 | 19년 전 | 3051 | ||
| 383 | 19년 전 | 3078 | ||
| 382 | 19년 전 | 3124 | ||
| 381 |
|
19년 전 | 2652 | |
| 380 |
|
19년 전 | 3034 | |
| 379 | 19년 전 | 2561 | ||
| 378 | 19년 전 | 2232 | ||
| 377 | 19년 전 | 2793 | ||
| 376 | 19년 전 | 2481 | ||
| 375 |
|
19년 전 | 2578 | |
| 374 | 19년 전 | 3837 | ||
| 373 | 19년 전 | 3289 | ||
| 372 | 19년 전 | 5013 | ||
| 371 |
세은아빠2
|
19년 전 | 2433 | |
| 370 | 19년 전 | 4515 | ||
| 369 | 19년 전 | 3121 | ||
| 368 | 19년 전 | 2920 | ||
| 367 | 19년 전 | 3746 | ||
| 366 | 19년 전 | 2673 | ||
| 365 | 19년 전 | 3759 | ||
| 364 | 19년 전 | 4036 | ||
| 363 | 19년 전 | 3471 | ||
| 362 | 20년 전 | 3503 | ||
| 361 | 20년 전 | 4128 | ||
| 360 |
hwatta
|
20년 전 | 2383 | |
| 359 | 20년 전 | 5126 | ||
| 358 | 20년 전 | 3675 | ||
| 357 | 20년 전 | 2621 | ||
| 356 |
sdesign1s
|
20년 전 | 2300 | |
| 355 | 20년 전 | 2778 | ||
| 354 | 20년 전 | 3042 | ||
| 353 | 20년 전 | 2808 | ||
| 352 |
|
20년 전 | 5789 | |
| 351 |
|
20년 전 | 2726 | |
| 350 |
|
20년 전 | 4314 | |
| 349 |
hwatta
|
20년 전 | 2208 | |
| 348 | 20년 전 | 7322 | ||
| 347 | 20년 전 | 2427 | ||
| 346 | 20년 전 | 3524 | ||
| 345 | 20년 전 | 4328 | ||
| 344 | 20년 전 | 2673 | ||
| 343 | 20년 전 | 3938 | ||
| 342 | 20년 전 | 3084 | ||
| 341 | 20년 전 | 4114 | ||
| 340 |
|
20년 전 | 5170 | |
| 339 |
|
20년 전 | 4254 | |
| 338 | 20년 전 | 5898 | ||
| 337 | 20년 전 | 2061 | ||
| 336 |
|
20년 전 | 3353 | |
| 335 |
|
20년 전 | 3570 | |
| 334 |
|
20년 전 | 2964 | |
| 333 |
hwatta
|
20년 전 | 2469 | |
| 332 | 20년 전 | 4672 | ||
| 331 | 20년 전 | 2296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기