채택완료

같은 서버입니다....A db에서 B db이동을 하려면~~

2016-11-25 (금) 10:30:52 2,619

A db에 있는 글을  B db에 복사를 하려합니다. 

 

마지막 하단에,  

원본DB AAA의 src 테이블(g5_write_aa) 내  wr_id = 1231 글입니다. 

타켓DB BBB의 tar 테이블(g5_write_bb)로 복사를 하려합니다. 

insert를 할 수 있는 방법이 있을까요?

<?php

// 1. 연결 : mysql_connect(호스트명, 아이디, 비밀번호)

$conn = mysql_connect('localhost', 'root', 'eofne.co'); //db 연결부분

// 2. DB 선택 : mysql_select_db(해당 db명, $conn)

$srcDB = mysql_select_db("AAA", $conn);

mysql_query('set names utf8');

$tarDB = mysql_select_db("BBB", $conn);

mysql_query('set names utf8');

//if($db)

// echo "db 연결성공";

//else

// echo "db 연결 실패";

// 3. DB에 table 쿼리(query 질의).

//$sql="create table php_tbl(num int, name varchar(10))";

// 4. DB 처리 echo "$sql";

//mysql_query($sql, $conn)  db에 질의 수행.

// DB에 table 쿼리(query 질의).

$srcTable = "g5_write_aa"; // source 테이블

$tarTable = "g5_write_bb"; // target 테이블 

$sql  = "insert into $tarTable (wr_subject, wr_content, wr_option, mb_id, wr_name, wr_datetime, wr_hit ) (select wr_subject, wr_content, wr_option, mb_id, wr_name, now(), wr_hit from $srcTable where wr_id =1231 " ;

mysql_query($sql_1st, $conn);

...

?>

|

답변 2개

채택된 답변
+20 포인트

A에서 글작성을하고

B의 db에 접속을하는 구성을 만들고

db접속이 되는지부터 차근차근 해보시는게 나을것같습니다.

db접속만되면 A글을 그대로 가져와서 넣는방법은 수월할듯합니다.

$conn  = mysql_connect(호스트, 계정, 비밀번호); //db 연결부분

mysql_query($sql, $conn);

$conn1 = mysql_connect(호스트, 계정, 비밀번호); //db 연결부분

mysql_query($sql, $conn1)

이런식으로 연결후 처리해 주시는 방법을 이용해 보세요

그리고 쿼리로는 조인이 안되니까 데이터를 불러와 그대로 insert 처리해 주시면 복사가 될겁니다.

답변을 작성하려면 로그인이 필요합니다.