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...)

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?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.