简体   繁体   English

INSERT INTO 3个表与一个表连接一次在php中查询

[英]INSERT INTO 3 tables joined with one table at once query in php

I'm trying to insert into, Update 3 tables joined with one table at once query using PHP, so I have the table "commandetb" who have the foreign key of tables = fournisseurtb, marchetb and marchetb table has a foreign key of datetb, so I have a form that has inputs for nomF, adrF, telF from fournisseurtb also objet_marche from marchetb and the last date_limite & heure_limite from datetb.我正在尝试插入,更新 3 个表与一个表连接,使用 PHP 一次查询,所以我有一个表“commandetb”,它的外键为表 =fournisseurtb,marchetb 和 Marchetb 表的外键为 datetb,所以我有一个表单,其中包含来自fournisseurtb 的nomF、adrF、telF 以及来自marchetb 的objet_marche 和来自datetb 的最后一个date_limite 和heure_limite。 who can help me to resolve this problem I appreciate that.谁能帮我解决这个问题,我很感激。 here's the script :这是脚本:

$sql="INSERT INTO `commandetb`(`date_cmd`,ID_marche,ID_f) VALUES('hhhh',,);
          INSERT INTO `fournisseurtb`(`nomF`,`adrF`,`telF`) VALUES(:znomF,:zadrF,:ztelF);
          INSERT INTO `marchetb`(`objet_marche`,ID_date) VALUES(:zobjet,LAST_INSERT_ID()) ";
    $stmt=$connectDB->prepare($sql);

    $stmt->bindValue(':znomF',$nomSoc);
    $stmt->bindValue(':zadrF',$adrSoc);
    $stmt->bindValue(':ztelF',$telSoc);
    $stmt->bindValue(':zobjet',$objet);
    
    $exec=$stmt->execute();

    if ($exec) {
        $sql2="INSERT INTO `datetb` (`date_limite`,`heure_limite`) VALUES(:zdateLimite,:zheureLimite)";
        $stmt2=$connectDB->prepare($sql2);
        $stmt2->bindValue(':zdateLimite',$dateLimite);
        $stmt2->bindValue(':zheureLimite',$heureLimite);
        $exec2=$stmt2->execute();
        if ($exec2) {
            $_SESSION['succesMessage']='La lettre est ajouté avec succes';
        }
    }
    else {
            $_SESSION['errorMessage']='il ya un problem d\'ajout, verifiez svp!';
        }

I use the stored procedure, but the problem doesn't resolve: Mysql code:我使用了存储过程,但问题没有解决: Mysql代码:

 CREATE PROCEDURE add_lettre(nomf varchar(50), adrf varchar(255), telf varchar(25), objetMarche varchar(500), dLimite varchar(25), hLimite varchar(25))

BEGIN INSERT INTO fournisseurtb(nomF,adrF,telF) VALUES(nomf,adrf,telf); BEGIN INSERT INTO Fournisseurtb(nomF,adrF,telF) VALUES(nomf,adrf,telf); INSERT INTO marchetb(objet_marche, ID_date) VALUES(objetMarche, LAST_INSERT_ID()); INSERT INTO Marchetb(objet_marche, ID_date) VALUES(objetMarche, LAST_INSERT_ID()); INSERT INTO datetb (date_limite,heure_limite) VALUES(dLimite,hLimite); INSERT INTO datetb (date_limite,heure_limite) VALUES(dLimite,hLimite); END结尾

PHP code : PHP代码:

$sql="CALL add_lettre(':znomF',':zadrF',':ztelF','zobjet',':zdateLimite',':zheureLimite')";
    $stmt=$connectDB->prepare($sql);

    $stmt->bindValue(':znomF',$nomSoc);
    $stmt->bindValue(':zadrF',$adrSoc);
    $stmt->bindValue(':ztelF',$telSoc);
    $stmt->bindValue(':zobjet',$objet);
    $stmt2->bindValue(':zdateLimite',$dateLimite);
    $stmt2->bindValue(':zheureLimite',$heureLimite);
    
    $exec=$stmt->execute();

    if ($exec) {
        
        $_SESSION['succesMessage']='La lettre est ajouté avec succes';
        
    }
    else {
            $_SESSION['errorMessage']='il ya un problem d\'ajout, verifiez svp!';
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM