Insertion and removal using PDO in OneToMany and ManyToMany relationships

0

I beginner questions about insertion and removal using PDO in relationships of type OneToMany and ManyToMany . Example:

class Livro{
   private $id;
   private $titulo;
   private $generos; //Livro tem mais de um genero
}

class Genero{
   private $id;
   private $nome;
}

The relationship is OneToMany, meaning a book has many genres. If in DB I have a JoinTable ( livro_genero ) how do insert using PDO ? What if the relationship is ManyToMany?

class Funcionario{
   private $id;
   private $nome;
   private $projetos; //Um funcionario pode participar de vários projetos
}

class Projeto{
   private $id;
   private $titulo;
   private $funcionarios; //Um projeto tem vários funcionarios
}

In the database I have the tables funcionario , projeto and funcionario_has_projeto .

PS: I can not use Doctrine, so I would like examples of how to do this without using an ORM and using MySQL.

    
asked by anonymous 29.05.2018 / 21:28

0 answers