erro com transação sql
Boa tarde galera do imasters.
Eu estou querendo fazer vários inserts simultâneos, só que em caso de erro, ele faria um rollback.
Só que esse meu insert está dando
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (eco_portaldb_homolog.trein_pf, CONSTRAINT fk_trein_pf_trein_pj1 FOREIGN KEY (_id_trein_pj) REFERENCES trein_pj (id_trein_pj) ON DELETE NO ACTION ON UPDATE NO ACTION)
Pois não está inserindo a pessoa jurídica para inserir os dados do usuário.
public function insert(){
try{
self::getInstance()->beginTransaction();
//insert manufactures
$insertPJ = "INSERT into trein_pj VALUES ( NULL,:cnpj,:razao_social,:nome_fantasia,:tel_comercial1,:tel_comercial2)";
$stmt = DB::prepare($insertPJ);
$stmt->bindParam(":cnpj",$this->cnpj,PDO::PARAM_STR);
$stmt->bindParam(":razao_social",$this->razao_social,PDO::PARAM_STR);
$stmt->bindParam(":nome_fantasia",$this->nomeFantasia,PDO::PARAM_STR);
$stmt->bindParam(":tel_comercial1",$this->tel_comercial1,PDO::PARAM_STR);
$stmt->bindParam(":tel_comercial2",$this->tel_comercial2,PDO::PARAM_STR);
$stmt->execute();
//insert peoples
$insertPF = "INSERT INTO trein_pf VALUES (NULL,:nome,:cargo,:rg,:cpf,:tel_fixo,:tel_celular,:email,:escolaridade,:formacao,:tempo_experciencia,:aceite,:data_registro,:ip_registro,:id_trein_pj,:id_treinamento)";
$stmt = DB::prepare($insertPF);
$stmt->bindParam(":nome",$this->nome,PDO::PARAM_STR);
$stmt->bindParam(":cargo",$this->cargo,PDO::PARAM_STR);
$stmt->bindParam(":rg",$this->rg,PDO::PARAM_STR);
$stmt->bindParam(":cpf",$this->cpf,PDO::PARAM_STR);
$stmt->bindParam(":tel_fixo",$this->tel_fixo,PDO::PARAM_STR);
$stmt->bindParam(":tel_celular",$this->tel_celular,PDO::PARAM_STR);
$stmt->bindParam(":email",$this->email,PDO::PARAM_STR);
$stmt->bindParam(":escolaridade",$this->escolaridade,PDO::PARAM_STR);
$stmt->bindParam(":formacao",$this->formacao,PDO::PARAM_STR);
$stmt->bindParam(":tempo_experciencia",$this->tempo_experiencia,PDO::PARAM_STR);
$stmt->bindParam(":aceite",$this->aceite,PDO::PARAM_STR);
$stmt->bindParam(":data_registro",$this->data_registro,PDO::PARAM_STR);
$stmt->bindParam(":ip_registro",$this->ip_registro,PDO::PARAM_STR);
$stmt->bindParam(":id_trein_pj",$this->id_trein_pj,PDO::PARAM_INT);
$stmt->bindParam(":id_treinamento",$this->id_treinamento, PDO::PARAM_INT);
return $stmt->execute();
}catch (PDOException $ex){
echo $ex->getMessage();
self::getInstance()->rollBack();
}
}Discussão (4)
Carregando comentários...