# L3BD - Groupe 3 - TD9 - 23-03-21 + TD10 30-03-21
#
``` php
// ============================ TD10 =================
// TD10 Question 2 //
<html>
<head>
<title></title>
</head>
<body bgcolor=lightgreen>
<? php
$idc = $_REQUEST['idc'];
$ville = $_REQUEST['ville'];
$jour = $_REQUEST['jour'];
$texte = "begin traitement2(".$idc.",".$ville.",".$jour.":1, :2, :3); end;";
$login= 'yghezal';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$ordre = ociparse($c, $texte);
ocibindbyname($ordre, ':1', $idv);
ocibindbyname($ordre, ':2', $ids);
ocibindbyname($ordre, ':3', $activite, 12);
ociexecute($ordre);
echo "idv : ".$idv;
echo "ids : ".$ids;
echo "activite : ".$activite;
ocilogoff($c);
?>
</body>
</html>
// TD10 Question 3 //
/* modele d'ordre :
traitement2(l_idc, la_ville, le_jour) :
select idv, prix, activite
from village
where ville = la_ville
order by prix decresc
renvoie resultat dans : l_idv, le_prix, l_activite;
si resultat existe alors
l_ids := seq_sejour.nextval; -- rem : il faut le renvoyer
insert into sejour
values(l_ids, l_idc, l_idv, le_jour);
update client
set avoir = avoir - le_prix
where idc = l_idc;
sinon
l_idv := -1;
l_ids = -1;
l_activite := 'neant';
retour traitement2 : l_idv, l_ids, l_activite;
*/
<html>
<body bgcolor =orange>
<?php
$l_idc = $_REQUEST['idc'];
$ville = $_REQUEST['ville'];
$jour = $_REQUEST['jour'];
$l_idv = -1;
$l_ids = -1;
$l_activite = 'neant';
$login= 'yghezal';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$texte = "SELECT idv, prix, activite
FROM village
WHERE ville = '".$ville."'
order by prix desc";
$ordre = ociparse($c, $texte);
ociexecute($ordre);
if(ocifetchinto($ordre, $ligne)) {
$l_idv = $ligne[0];
$prix = $ligne[1];
$l_activite = $ligne[2];
$texte = "SELECT seq_sejour.nextval FROM dual";
$ordre = ociparse($c, $texte);
ociexecute($ordre);
ocifetchinto($ordre, $ligne);
$l_ids = $ligne[0];
$texte = "INSERT INTO sejour
VALUES (".$l_ids.",".$l_idc.",".$l_idv.", ".$jour.")";
$ordre = ociparse($c,$texte);
ociexecute($ordre);
$texte = "UPDATE client SET avoir = avoir - ".$prix."
WHERE idc = ".$l_idc;
$ordre = ociparse($c, $texte);
ociexecute($ordre);
} else {
echo "aucun sejour disponible";
}
echo "id village :".$l_idv."<br/>";
echo "id sejour :".$l_ids."<br/>";
echo "activite :".$l_activite."<br/>";
ocilogoff($c);
?>
</body>
</html>
// TD9 question 4 //
<html>
<head>
<title></title>
</head>
<body bgcolor=lightblue>
<?php
$texte="begin :1 := traitement3(".$_REQUEST['jour']."); end;";
$login= 'yghezal';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$ordre = ociparse($c, $texte);
ocibindbyname($ordre, ':1', $z);
ociexecute($ordre);
echo "nb de jours supprimés: ".$z;
ocilogoff($c);
?>
</body>
</html>
<html>
<body bgcolor=orange>
<?php
$texte = "begin traitement3_out(".$_REQUEST['jour'].", :1); end;";
$login= 'yghezal';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$ordre = ociparse($c, $texte);
ocibindbyname($ordre, ':1', $z);
ociexecute($ordre);
echo "nb de jours supprimés: ".$z;
ocilogoff($c);
?>
</body>
</html>
// ============================ TD9 =================
// (2)
// Traitement 3
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
// URL .... http://....../nomprogramme.php?formulaire_jour=17
// '\n' non interpreté - "\n" -> retour ligne
$nb_jour = $_REQUEST['formulaire_jour'];
$login = 'acombe';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$texte = "delete from sejour where jour < ".$nb_jour;
echo "(debug : ".$texte.")<br>\n";
$ordre = ociparse($c, $texte);
ociexecute($ordre);
echo "Nombre de ligne delete = ".oci_num_rows($ordre);
ocilogoff($c);
?>
</body>
</html>
//# (3)
//# action des clients
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$nom_client = $_REQUEST['nom'];
$idc_client = $_REQUEST['idc'];
$login = 'acombe1';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$texte = "select * from Client where "
." nom = '".$nom_client."'"
." and idc = ".$idc_client;
$ordre = ociparse($c, $texte);
ociexecute($ordre);
if (ocifetchinto($ordre, $ligne)) {
echo "nom-idc dans la bdd";
//faire la redirection vers la page permettant les actions 1 et 2
echo "bienvenue ".$ligne[0].", ".$ligne[1].", ".$ligne[2].", ".$ligne[3];
} else {
echo "nom-idc inconnu";
}
ocilogoff($c);
?>
</body>
</html>
//# (5)
//#
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$idc_client = $_REQUEST['idc'];
$login = 'acombe';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$texte = " SELECT village.idv,ville,activite,prix,capacite "
." FROM sejour,village WHERE "
." village.idv = sejour.idv AND sejour.idc = ".$idc_client;
$ordre = ociparse($c, $texte);
ociexecute($ordre);
while(ocifetchinto($ordre,$ligne)) {
echo "Village : idc = ".$ligne[0]." ville = ".$ligne[1]
." activite = ".$ligne[2]." prix = ".$ligne[3]
." prix = ".$ligne[4]."<br/>"; // <br> </br> <br/>
}
ocilogoff($c);
?>
</body>
</html>
//# (6)
//#inscription client
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$nom_client = $_REQUEST['nom'];
$age_client = $_REQUEST['age'];
$login = 'acombe';
$c = ocilogon('c##'.$login.'_a',$login.'_a', 'dbinfo');
$texte_seq =" SELECT seq_client.nextval FROM dual";
$ordre_seq = ociparse($c, $texte_seq);
ociexecute($ordre_seq);
ocifetchinto($ordre_seq, $ligne);
$idc = $ligne[0];
$texte_insert = "INSERT INTO client (idc,nom,age) VALUES ("
.$idc.",'".$nom_client."', ".$age_client.")";
$ordre_insert = ociparse($c, $texte_insert);
if (ociexecute($ordre_insert)) {
echo "inscription correcte votre identifiant est : " .$idc;
} else {
echo "erreur d'inscription";
}
ocilogoff($c);
?>
</body>
</html>
```