Guest User

Untitled

a guest
Nov 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. // include_once 'conexao.php';
  3. function getConnection(){
  4. $host = "localhost";
  5. $user = "root";
  6. $pass = "";
  7. $db_name = "pdo";
  8. try{
  9. $conecta = new PDO("mysql:host=".$host.";dbname=".$db_name, $user, $pass);
  10. return array("conexao" => $conecta, "mensagem" => "Sucesso");
  11. } catch(PDOException $e){
  12. return array("conexao" => null, "mensagem" => "Algo de errado não está certo. <br> Erro: " . $e -> getMessage());
  13. }
  14. }
  15. $conecta = getConnection();
  16. $tipo = "Tipo";
  17. $tamanho = "1M";
  18. $nome = "Prod";
  19. // $sql = "INSERT INTO produtos (nome, tamanho, tipo) VALUES (:nome, :tamanho, :tipo)";
  20. // $stmt = $conecta->prepare($sql);
  21. $stmt = $conecta->prepare("INSERT INTO produtos (nome, tamanho, tipo) VALUES (:nome, :tamanho, :tipo)");
  22. $stmt->bindParam( ':nome', $nome );
  23. $stmt->bindParam( ':tamanho', $site );
  24. $stmt->bindParam( ':tipo', $tipo );
  25. if ($stmt->execute()) {
  26. echo "Dados Salvos " . $nome;
  27. }else{
  28. echo "Ocoreu um erro " . $nome;
  29. }
  30.  
  31. ?>
Add Comment
Please, Sign In to add comment