1 |
aurelien |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
// Programme de migration jetable
|
|
|
5 |
include_once 'connect.php';
|
|
|
6 |
//bouh! c'est pas propre! c'est a cause de PEAR et de ses includes
|
|
|
7 |
set_include_path('configuration/'.PATH_SEPARATOR.get_include_path());
|
|
|
8 |
//librairies PEAR
|
|
|
9 |
require_once 'configuration/DB.php' ;
|
|
|
10 |
$dsn='mysql://'.$login.':'.$pass.'@'.$hote.'/'.$db;
|
|
|
11 |
//echo $dsn.'<br /><br />';
|
|
|
12 |
$GLOBALS['car_db'] =& DB::connect($dsn) ;
|
|
|
13 |
if (DB::isError($GLOBALS['car_db'])) {
|
|
|
14 |
die ($GLOBALS['car_db']->getMessage());
|
|
|
15 |
}
|
|
|
16 |
|
|
|
17 |
$requete = 'SELECT SEQUENCE_ID, ESPECE_ID, SEQUENCE.COMMUNE_ID, STATION_ID, SEQUENCE_ALTITUDE, ENVIRONNEMENT_ID, PARTICIPANT_ID, COMMUNE_NOM, COMMUNE_LATITUDE, COMMUNE_LONGITUDE, COMMUNE_ALTITUDE FROM SEQUENCE, COMMUNE WHERE SEQUENCE.COMMUNE_ID=COMMUNE.COMMUNE_ID ';
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
$resultat = $GLOBALS['car_db']->query($requete) ;
|
|
|
21 |
|
|
|
22 |
if (DB::isError($resultat)) {
|
|
|
23 |
die ($resultat->getMessage());
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
$i=1;
|
|
|
27 |
|
|
|
28 |
while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
|
|
|
29 |
|
|
|
30 |
// $alt = file_get_contents('http://ws.geonames.org/srtm3?lat='.$ligne['COMMUNE_LATITUDE'].'&lng='.$ligne['COMMUNE_LONGITUDE'], 'r') ;
|
|
|
31 |
$alt=0;
|
|
|
32 |
|
|
|
33 |
$requete2 = 'INSERT INTO STATION (PARTICIPANT_ID, STATION_NOM, STATION_LATITUDE , STATION_LONGITUDE, STATION_ALTITUDE, STATION_ENVIRONNEMENT_ID)' .
|
|
|
34 |
' VALUES ('.$ligne['PARTICIPANT_ID'].',\''.addslashes($ligne['COMMUNE_NOM']).'\','.$ligne['COMMUNE_LATITUDE']. ','.$ligne['COMMUNE_LONGITUDE']. ','.$alt.','.$ligne['ENVIRONNEMENT_ID'].');';
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
echo $requete2.'<br/>';
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
$requete3= 'UPDATE SEQUENCE SET STATION_ID='.$i.' WHERE SEQUENCE_ID='.$ligne['SEQUENCE_ID'].';';
|
|
|
42 |
|
|
|
43 |
echo $requete3.'<br/>';
|
|
|
44 |
|
|
|
45 |
$i++;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
}
|
|
|
49 |
?>
|