<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   <head>
        <title>Transfert SQL</title>
        <meta http-equiv="Pragma" content="no-cache" /> 
        <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />  
        <meta http-equiv="Expires" content="0" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
        <body>
        <?php                           
        // bts2m.free.fr/Wifi/VI_telecharge.php?table=1       
        //--Connexion au serveur
        define("NOM","tpil.projet");            //nom = login chez free
        define("PASSE","MotDePasse");          // passe=votre mot de passe free
        define("SERVEUR","sql.free.fr");     // adresse du serveur free
        $link = mysql_connect(SERVEUR,NOM,PASSE);
        $table='mesures';
        $titre='mesuresTitre';
        
        if(!$link) {echo"Impossible de se connecter au serveur".mysql_error();exit;}
                    else {echo "<h2>Connexion au serveur réussie !</h2>\n";}
        
            if (isset($_GET['table'])) {
            $table='mesures'.$_GET['table'];
            $titre='mesuresTitre'.$_GET['table'];
            echo "<p>Table : ".$table."  Titre : ".$titre."</p>\n";
            }
                
        mysql_select_db($table,$link);
        $requete= "SELECT * FROM ".$table." ORDER BY `id` ASC";
        $reponse=mysql_query($requete, $link);       
        if(!$reponse) {echo"Echec de lecture de la base de données <br>".mysql_error();exit;}
        echo 'Debut';
        while($ligne=mysql_fetch_array($reponse, MYSQL_ASSOC))          // lecture d'une ligne (ou une entrée) de la base de données puis auto incrémentation
            {   $dateUnix= strtotime ($ligne[date]);
                $M1=$ligne[mesure1];
                $M2=$ligne[mesure2];
                $M3=$ligne[mesure3];
                echo $ligne[id].";".$dateUnix.";".$M1.";".$M2.";".$M3."\n";
            }
        echo 'Fin\n';
        
        mysql_select_db($titre,$link);
        $requete= "SELECT * FROM ".$titre." ORDER BY `id` ASC";
        if ($reponse=mysql_query($requete, $link)) {
            $ligne=mysql_fetch_array($reponse, MYSQL_ASSOC);
            echo "<p>TitreM1=".$ligne[titre].". UnitM1=".$ligne[unit]."</p>\n";
            $ligne=mysql_fetch_array($reponse, MYSQL_ASSOC);
            echo "<p>TitreM2=".$ligne[titre].". UnitM2=".$ligne[unit]."</p>\n";
            $ligne=mysql_fetch_array($reponse, MYSQL_ASSOC);
            echo "<p>TitreM3=".$ligne[titre].". UnitM3=".$ligne[unit]."</p>\n";     
        }
        else // Sinon, on affiche un message d'erreur
                {echo '<p>Pas de transmission</p><p>Rappel format : /Wifi/VI_recup?table=1</p>\n';}
        
        mysql_close($link);
        ?>
    </body>
</html>