par
yoann38 » 30 sept. 2019, 17:20
Bonjour tout le monde.
Voilà je réalisé un insert en bdd mais je pense m'embrouiller dans mon INSERT car j'ai une petite problématique c'est en fait un double INSERT, sur 2 tables donc
entreprise et
horaire
Au cours du premier insert j'auto incrémente mon
id de ma table
entreprise mais j'ai besoin de le récupérer mon ensuite l'intégrer dans mon 2ème insert car effectivement cet
id correspond à
id_entreprise de mon 2ème insert
J'ai réduit le code PHP pour en facilité sa compréhension
// Insert entreprise
$req = $bdd->prepare("INSERT INTO entreprise (`nom_etablissement`) VALUES (:nom_etablissement");
$req->bindParam(':nom_etablissement', $_POST['nom_etablissement'], PDO::PARAM_STR);
// Insert Horaires
$req2 = $bdd->prepare("INSERT INTO hoaires (`id_entreprise`, jour, opening, ouverture, fermeture) VALUES (:id_entreprise, :jour, :opening, :ouverture, :fermeture");
$req2->bindParam(':id_entreprise', $_POST['id_bar'], PDO::PARAM_STR);
$req2->bindParam(':jour', $jour, PDO::PARAM_STR);
$req2->bindParam(':opening', $_POST['opening'], PDO::PARAM_STR);
$req2->bindParam(':ouverture', $_POST['ouverture'], PDO::PARAM_STR);
$req2->bindParam(':fermeture', $_POST['fermeture'], PDO::PARAM_STR);
$req2->execute();
Bonjour tout le monde.
Voilà je réalisé un insert en bdd mais je pense m'embrouiller dans mon INSERT car j'ai une petite problématique c'est en fait un double INSERT, sur 2 tables donc [b]entreprise [/b]et [b]horaire[/b]
Au cours du premier insert j'auto incrémente mon [b]id [/b]de ma table [b]entreprise[/b] mais j'ai besoin de le récupérer mon ensuite l'intégrer dans mon 2ème insert car effectivement cet [b]id[/b] correspond à [b]id_entreprise[/b] de mon 2ème insert
[b]J'ai réduit le code PHP pour en facilité sa compréhension [/b]
[PHP]
// Insert entreprise
$req = $bdd->prepare("INSERT INTO entreprise (`nom_etablissement`) VALUES (:nom_etablissement");
$req->bindParam(':nom_etablissement', $_POST['nom_etablissement'], PDO::PARAM_STR);
// Insert Horaires
$req2 = $bdd->prepare("INSERT INTO hoaires (`id_entreprise`, jour, opening, ouverture, fermeture) VALUES (:id_entreprise, :jour, :opening, :ouverture, :fermeture");
$req2->bindParam(':id_entreprise', $_POST['id_bar'], PDO::PARAM_STR);
$req2->bindParam(':jour', $jour, PDO::PARAM_STR);
$req2->bindParam(':opening', $_POST['opening'], PDO::PARAM_STR);
$req2->bindParam(':ouverture', $_POST['ouverture'], PDO::PARAM_STR);
$req2->bindParam(':fermeture', $_POST['fermeture'], PDO::PARAM_STR);
$req2->execute();
[/PHP]