Skip navigation links

MySQL Forums :: PHP :: html,mysql,php copy data from one db to another


Advanced Search

Re: html,mysql,php copy data from one db to another
Posted by: brian liddle ()
Date: June 14, 2012 02:38PM

updated code as you said. still fails to display anything at all. no errors or table.

code:

<html>
<body>

<?php

//Part 1: get data to copy
$con = mysql_connect("IPADDRESS","USERNAME","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("DATABASE", $con);

$MainResult = mysql_query("SELECT column1
,column2
,column3
,column4
,column5
,column6
,column7
,column8
,column9
,column10
,column11
,column12
,column13
,column14
,column15
,column16
,column17
FROM TABLE");

mysql_close($con);

// Done with part 1: get data to copy

//Part 2: Insert and Update with new data
$con = mysql_connect("IPADDRESS","USERNAME","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("DATABASE", $con);


while ($row = mysql_fetch_row($MainResult))
{
mysql_query("INSERT INTO TABLE VALUES ('".mysql_real_escape_string($row[0])."',
$row[1],
'".mysql_real_escape_string($row[2])."',
$row[3],
'".mysql_real_escape_string($row[4])."',
'".mysql_real_escape_string($row[5])."',
'".mysql_real_escape_string($row[6])."',
'".mysql_real_escape_string($row[7])."',
'".mysql_real_escape_string($row[8])."',
'".mysql_real_escape_string($row[9])."',
'".mysql_real_escape_string($row[10])."',
'".mysql_real_escape_string($row[11])."',
'".mysql_real_escape_string($row[12])."',
'".mysql_real_escape_string($row[13])."',
'".mysql_real_escape_string($row[14])."',
'".mysql_real_escape_string($row[15])."',
'".mysql_real_escape_string($row[16])."',
NULL)
ON DUPLICATE KEY UPDATE TABLE SET COLUMN1='".mysql_real_escape_string($row[0])."',
COLUMN2=$row[1],
COLUMN3='".mysql_real_escape_string($row[2])."',
COLUMN4=$row[3],
COLUMN5='".mysql_real_escape_string($row[4])."',
COLUMN6='".mysql_real_escape_string($row[5])."',
COLUMN7='".mysql_real_escape_string($row[6])."',
COLUMN8='".mysql_real_escape_string($row[7])."',
COLUMN9='".mysql_real_escape_string($row[8])."',
COLUMN10='".mysql_real_escape_string($row[9])."',
COLUMN11='".mysql_real_escape_string($row[10])."',
COLUMN12='".mysql_real_escape_string($row[11])."',
COLUMN13='".mysql_real_escape_string($row[12])."',
COLUMN14='".mysql_real_escape_string($row[13])."',
COLUMN15='".mysql_real_escape_string($row[14])."',
COLUMN16='".mysql_real_escape_string($row[15])."',
COLUMN17='".mysql_real_escape_string($row[16])."';")
}
//Done with part 2: Insert and Update with new data

//Part 3: Print Data from Updated DB
$MirrorResult = mysql_query("SELECT * FROM TABLE");

$fields_num = mysql_num_fields($MirrorResult);
echo '<table border="1"><tr>';
$fields = mysql_query("DESCRIBE TABLE;");
while ($row = mysql_fetch_row($fields))
{
echo "<th>";
echo $row[0];
echo "</th>";
}
echo "</tr>";
while($row = mysql_fetch_row($MirrorResult))
{
echo "<tr>";
echo "<td>";
echo $row[0];
echo "</td>";
echo "<td>";
echo $row[1];
echo "</td>";
echo "<td>";
echo $row[2];
echo "</td>";
echo "<td>";
echo $row[3];
echo "</td>";
echo "<td>";
echo $row[4];
echo "</td>";
echo "<td>";
echo $row[5];
echo "</td>";
echo "<td>";
echo $row[6];
echo "</td>";
echo "<td>";
echo $row[7];
echo "</td>";
echo "<td>";
echo $row[8];
echo "</td>";
echo "<td>";
echo $row[9];
echo "</td>";
echo "<td>";
echo $row[10];
echo "</td>";
echo "<td>";
echo $row[11];
echo "</td>";
echo "<td>";
echo $row[12];
echo "</td>";
echo "<td>";
echo $row[13];
echo "</td>";
echo "<td>";
echo $row[14];
echo "</td>";
echo "<td>";
echo $row[15];
echo "</td>";
echo "<td>";
echo $row[16];
echo "</td>";
echo "<td>";
echo $row[17];
echo "</td>";
echo "</tr>\n";
}
echo "</table>";

mysql_free_result($MainResult);
mysql_free_result($MirrorResult);

mysql_close($con);
//Done with part 3: Print Data from Updated DB
?>

</body>
</html>

Options: ReplyQuote


Subject Written By Posted
html,mysql,php copy data from one db to another brian liddle 06/01/2012 04:51PM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/01/2012 06:45PM
Re: html,mysql,php copy data from one db to another brian liddle 06/04/2012 11:08AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/04/2012 06:02PM
Re: html,mysql,php copy data from one db to another brian liddle 06/05/2012 08:39AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/05/2012 06:30PM
Re: html,mysql,php copy data from one db to another brian liddle 06/06/2012 08:37AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/06/2012 07:16PM
Re: html,mysql,php copy data from one db to another brian liddle 06/07/2012 10:28AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/07/2012 08:19PM
Re: html,mysql,php copy data from one db to another brian liddle 06/08/2012 09:09AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/08/2012 07:43PM
Re: html,mysql,php copy data from one db to another brian liddle 06/14/2012 02:38PM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/14/2012 05:47PM
Re: html,mysql,php copy data from one db to another brian liddle 06/15/2012 10:25AM
Re: html,mysql,php copy data from one db to another Barry Galbraith 06/17/2012 04:55PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.