Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2. namespace Insert;
  3. class InsertProduct extends Product
  4. {
  5.  
  6. private $user = "root";
  7. private $pass = "root";
  8. private $dsn = "mysql:dbname=formacao_php;host=localhost";
  9.  
  10. public function insert(Product $inserir){
  11.  
  12. $pdo = new PDO($dsn,$user,$pass);
  13.  
  14. $sql = "INSERT INTO produtos(nome, descricao, preco) values ( :nome, :descricao, :preco)";
  15.  
  16. $insert=$pdo->prepare($sql);
  17. $insert->bindvalue(":nome", $inserir->getProduct(), PDO::PARAM_STR);
  18. $insert->bindvalue(":descricao", $inserir->getDescription(), PDO::PARAM_STR);
  19. $insert->bindvalue(":preco", $inserir->getPrice(), PDO::PARAM_STR);
  20.  
  21. if($insert->execute()){
  22. echo "Registro inserido com sucesso com o número de ID ".$pdo->lastInsertId();
  23. }
  24. else{
  25. echo "Erro!";
  26. }
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement