INSERT .. SELECT sur 2 BDD
Bonjour,
J'ai une erreur dans ma requête, qqu pourrais m'aider?
La table se nomme PLD_LINK dans les deux BDD.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?php
$host1 = "localhost";
$user1 = "admin1";
$pass1 = "password1";
$dbname1 = "name1";
$host2 = "localhost";
$user2 = "admin1";
$pass2 = "password2";
$dbname2 = "name2";
$db2 = mysql_connect($host2,$user2,$pass2) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname2,$db2);
$db1 = mysql_connect($host1,$user1,$pass1) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname1,$db1);
$req=("INSERT INTO $dbname2.PLD_LINK (ID,TITLE,DESCRIPTION,URL)
SELECT PLD_LINK.ID,PLD_LINK.TITLE,PLD_LINK.DESCRIPTION,PLD_LINK.URL
FROM PLD_LINK Where ID=280");
$result=mysql_query($req);
?> |
Voici ce que j'ai trouvé sur la copie d'un enregistrement entre 2 BDD
Using INSERT INTO ... SELECT you can copy data from one database to another. You need the correct privileges for both.
Enter the source database, database1:
use database1;
Then write to which fields in the destination database you want to copy to, database2:
Code:
1 2 3
| INSERT INTO database2.table1 (field1,field3,field9)
SELECT table2.field3,table2.field1,table2.field4
FROM table2; |
The order of the selected fields and the inserted fields must match, so you enter the correct data. Before doing this, use "describe database2.table1" and "describe database1.table2", to make sure the new fields can hold the same kind of information.