bonjour je suis un etudiant j ai un devoir en mysql&php ; je doit utilise un autocommit mais je sais pas comment faire merci pour votre idee a l avance
C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\Projet_php\modele\fiche.php
C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\Projet_php\fonctions_html\fiche.php
Code PHP : 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 <?php function get_infos_film($id_film) { global $bdd; $requete = $bdd->prepare('SELECT * FROM films WHERE id_film = ?'); $requete->execute(array($id_film)); $reponse = $requete->fetch(); $requete->closecursor(); return $reponse; } function get_seances_film($id_film) { global $bdd; $sauvegarde = array(); $i = 0; $requete = $bdd->prepare('SELECT * FROM seances WHERE id_film = ?'); $requete->execute(array($id_film)); while($donnees = $requete->fetch()) { $sauvegarde[$i] = $donnees; $i++; } $requete->closecursor(); $sauvegarde['taille'] = $i; return $sauvegarde; } function deja_inscrit($id_seance, $login) { global $bdd; $requete = $bdd->prepare('SELECT COUNT(id_seance) as rep FROM inscriptions WHERE id_seance = ? AND login = ?'); $requete->execute(array($id_seance, $login)); $reponse = $requete->fetch(); $requete->closecursor(); return $reponse['rep'] == 1; } function seance_pleine($id_seance) { global $bdd; $requete = $bdd->query('SELECT COUNT(login) as rep FROM inscriptions WHERE id_seance = ' . $id_seance); $nb_inscriptions = $requete->fetch(); $requete->closecursor(); $requete = $bdd->query('SELECT max FROM seances WHERE id_seance = ' . $id_seance); $nb_max_inscriptions = $requete->fetch(); $requete->closecursor(); return $nb_inscriptions['rep'] == $nb_max_inscriptions['max']; } function inscrire_a_une_seance($id_seance, $login) { global $bdd; $bdd->exec('INSERT INTO inscriptions(id_seance, login) VALUES(' . $id_seance . ',\'' . $login . '\')'); } function desinscrire_d_une_seance($id_seance, $login) { global $bdd; $bdd->exec('DELETE FROM inscriptions WHERE id_seance = ' . $id_seance . ' AND login = \'' . $login . '\''); } function supprimer_seance($id_seance) { global $bdd; $requete = $bdd->prepare('SELECT COUNT(id_seance) as rep FROM inscriptions WHERE id_seance = ?'); $requete->execute(array($id_seance)); $reponse = $requete->fetch(); $requete->closecursor(); if($reponse['rep'] == 0) { $bdd->exec('DELETE FROM seances WHERE id_seance = ' . $id_seance); return true; } else return false; }
Code PHP : 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 <?php include_once("modele/fiche.php"); function afficher_seances($id_film) { $liste_seance = get_seances_film($id_film); echo '<table STYLE="border:none;width:100%;">'; echo '<tr><td>Date</td><td>Heure</td></tr>'; for($i=0;$i<$liste_seance['taille'];$i++) { echo '<form method="post" action="index.php?p=fiche&id=' . $_GET['id'] . '">'; echo '<tr>'; echo '<input type="hidden" name="seance" value="' . $liste_seance[$i]['id_seance'] . '" />'; echo '<td>' . $liste_seance[$i]['date'] . '</td>'; echo '<td>' . $liste_seance[$i]['heure'] . '</td>'; if(!deja_inscrit($liste_seance[$i]['id_seance'], $_SESSION['login'])) echo '<td><input type="submit" name="action" value="S\'inscrire" /></td>'; if(deja_inscrit($liste_seance[$i]['id_seance'], $_SESSION['login'])) echo '<td><input type="submit" name="action" value="Se désinscrire" /></td>'; if(seance_pleine($liste_seance[$i]['id_seance'])) echo '<td><strong><font color="red">Pleins !</font></strong></td>'; if(isset($_SESSION['connecter']) AND $_SESSION['connecter'] AND isset($_SESSION['user']) AND $_SESSION['user'] == 'admin') echo '<td><input STYLE="color:red;width:100px;" type="submit" name="action" value="Supprimer" /></td>'; echo '</tr>'; echo '</form>'; } echo '</table>'; }
C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\Projet_php\controleur\fiche.php
Code PHP : 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
28
29
30
31
32
33
34
35 <?php include_once('modele/fiche.php'); include_once('fonctions_html/fiche.php'); if(isset($_POST['action']) AND preg_match("#S'inscrire|Se désinscrire|Supprimer#", $_POST['action'])) { switch($_POST['action']) { case "S'inscrire" : if(!deja_inscrit($_POST['seance'], $_SESSION['login'])) { if(!seance_pleine($_POST['seance'])) inscrire_a_une_seance($_POST['seance'], $_SESSION['login']); } else header('Location:index.php?p=hacker'); break; case "Se désinscrire" : if(deja_inscrit($_POST['seance'], $_SESSION['login'])) desinscrire_d_une_seance($_POST['seance'], $_SESSION['login']); else header('Location:index.php?p=hacker'); break; case "Supprimer" : if(!supprimer_seance($_POST['seance'])) $erreur = 'Il y a des personnes inscrites à à cette séance !'; break; default: header('Location:index.php?p=accueil'); break; } } if(isset($_GET['id'])) $infos = get_infos_film($_GET['id']); if(!(empty($infos))) { $titre_film = $infos['titre']; $image = $infos['image']; $genre = $infos['genre']; $synopsis = $infos['synopsis']; } include_once('vue/fiche.php');
le devoir c'est de change la partie en rouge et la rendre en mode transactionnelle en doit utilise beginTransaction ....
mais je sais pas comment rendre cette function dans ce mode![]()
Partager