Jump to content

fetch and insert into two db


fer0an

Recommended Posts

When copying from one database to another, you have to extract first, then switch connections with 'use' then insert into the other

Only if the two databases are on different servers

 

(But you might also be so polite to react on what another person is saying, without repeating yourself...)

Link to comment
Share on other sites

I've fetch my data with this code :

[color=red]
$query = mysql_query("SELECT * FROM  jos_mxc_admcomments")
or die(mysql_error()); 
$row = mysql_fetch_array( $query );
$id= $row['contentid'];
$comment = $row['comment'];
   
while ($row = mysql_fetch_array( $query ))
{
echo $row['contentid'];
echo $row['comment'];
}
mysql_close($con);[/color]

then I want insert into db2 :

[color=red]

//connecting db2
$con1 = mysql_connect($dbhost1, $dbuser1, $dbpass1);
mysql_select_db($dbname1) or die('Could not select database');

{
    $insert1 = "INSERT INTO `jos_jcomments` (
`id` ,
`parent` ,
`object_id` ,
`object_group` ,
`object_params` ,
`lang` ,
`userid` ,
`name` ,
`username` ,
`email` ,
`homepage` ,
`title` ,
`comment` ,
`ip` ,
`date` ,
`isgood` ,
`ispoor` ,
`published` ,
`subscribe` ,
`source` ,
`checked_out` ,
`checked_out_time` ,
`editor`
)
VALUES (
NULL , '0', '".$id1."', 'com_content', '', '', '0', '', '', '', '', '', '".$title."', '', '".date('Y-m-d G:i:s')."', '0', '0', '1', '0', '', '0', '".date('Y-m-d G:i:s')."', ''
)";
if(!mysql_query($insert1,$con1))
  {
   die('Error:2vomi'. mysql_error()  );

}
}
[/color]

 

anyone can help me about this codes?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.