Guest User

Untitled

a guest
Jun 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. function __autoload($class) {
  2. $class = strtolower($class);
  3. // Inclui a classe que precisamos
  4. include_once("classes/class-{$class}.php");
  5. }
  6.  
  7. class ConnectionFactory{
  8. static function getConnection(){
  9. $con = new PDO("mysql:host=localhost;dbname=projeto_php_pdo", "root", "");
  10. return $con;
  11. }
  12. }
  13.  
  14. class metodosPDO {
  15.  
  16. function __autoload($class) {
  17. $class = strtolower($class);
  18. // Inclui a classe que precisamos
  19. include_once("classes/class-{$class}.php");
  20. }
  21.  
  22. static function inserirCliente($nome, $sobrenome) {
  23. $con = ConnectionFactory::getConnection();
  24. $stmt = $con->prepare("INSERT INTO pessoa(nome, sobrenome) VALUES(?, ?)");
  25. $stmt->bindParam(1, $nome);
  26. $stmt->bindParam(2, $sobrenome);
  27. $stmt->execute();
  28. $stmt->close();
  29. return;
  30. }
  31. }
  32.  
  33. <?PHP
  34. // INCLUIR AQUI
  35. ?>
  36. <form action="#" method="post">
  37. <input type="text" name="nome" value="" />
  38. <input type="text" name="sobrenome" value="" />
  39. <input type="submit" value="Cadastrar" name="btn" />
  40. </form>
  41.  
  42. <?php
  43. $nome = $_POST['nome'];
  44. $sobrenome = $_POST['sobrenome'];
  45. $verf = metodosPDO::inserirCliente($nome, $sobrenome);
  46. ?>
Add Comment
Please, Sign In to add comment