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
| <?php
global $dbh;
$user = 'root';
$password = '';
$dsn = 'mysql:host=localhost;dbname=info';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
print "Erreur ! : " . $e->getMessage() . "<br/>";
die();
}
$site_id = '';
$liste_societe_id = '';
$adresse_id = '';
try{
$dbh->beginTransaction();
// Création du site
$sql1 = "INSERT INTO site (nom, alias, commentaires)
VALUES ('".$_POST[nom_site]."',
'".$_POST[alias_site]."',
'".$_POST[commentaires]."');";
$dbh->exec($sql1);
$site_id = $dbh->lastInsertId();
// Création de l'adresse LAST_INSERT_ID
$sql2 = "INSERT INTO adresse (site_id, adresse, code_postal, ville, pays, tel, fax, contact)
VALUES ('".$site_id."',
'".$_POST[adresse]."',
'".$_POST[code_postal]."',
'".$_POST[ville]."',
'".$_POST[pays]."',
'".$_POST[tel]."',
'".$_POST[fax]."'
'".$_POST[contact]."');";
$dbh->exec($sql2);
$adresse_id = $dbh->lastInsertId();
// Création de la société
$sql3 = "INSERT INTO liste_societe (code_societe, societe, adresse, code_postal, ville, pays, tel, fax, siren, siret, ape, cpte_clt_orange_m)
VALUES ('".$_POST[code_societe]."',
'".$_POST[societe]."',
'".$_POST[adresse]."',
'".$_POST[code_postal]."',
'".$_POST[ville]."',
'".$_POST[pays]."',
'".$_POST[tel]."',
'".$_POST[fax]."',
'".$_POST[siren]."',
'".$_POST[siret]."',
'".$_POST[ape]."',
'".$_POST[cpte_clt_orange_m]."');";
$dbh->exec($sql3);
$liste_societe_id = $dbh->lastInsertId();
// Création du lien adresse société
$sql4 = "INSERT INTO societe (adresse_id, liste_societe_id)
VALUES ('".$adresse_id."', '.$liste_societe_id');";
$dbh->exec($sql4);
$dbh->commit();
} catch (Exception $e){
$dbh->rollBack();
}
global $dbh;
$dbh = NULL;
?> |
Partager