Bonjour,
Je souhaite faire un select d'une base Oracle puis inserer le résultat dans une base MySql en utilisant PDO.
Mon code fonctionne correctement mais je ne pense pas qu'il soit bien optimisé.
Auriez des commentaires sur la méthode la plus performante.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 try { $db = new PDO("odbc:wh", 'wh', 'wh'); $dbup = new PDO('mysql:host=localhost;dbname=uat', 'root', ''); //select all lines from the Oracle DB $result = $db->prepare('SELECT * FROM item_master WHERE ROWNUM <= 5000'); foreach($result as $row) { //Insert all lines in the MySql DB $dbup->exec("INSERT INTO item_master (SKU_ID,SIZE_DESC) VALUES ('" . $row['SKU_ID'] . "','" . $row['SIZE_DESC'] . "')") or die(print_r($dbup->errorInfo(), true)); } // close the database connection $db = NULL; $dbup = NULL; } catch(PDOException $e) { print 'Exception : '.$e->getMessage(); }
Partager