Include PHP class (PDO)

0

Well, I started my PDO studies recently, I'm trying to include a class in a form, but it's giving the error:

  

failed to open stream:

  function __autoload($class) {
        $class = strtolower($class);
        // Inclui a classe que precisamos
        include_once("classes/class-{$class}.php");
    }

ConnectionFactory.php

   class ConnectionFactory{
       static function getConnection(){
        $con = new PDO("mysql:host=localhost;dbname=projeto_php_pdo", "root", ""); 
    return $con;
       }
    }

MetodosPDO.php

   class metodosPDO {

       function __autoload($class) {
          $class = strtolower($class);
          // Inclui a classe que precisamos
          include_once("classes/class-{$class}.php");
        }

       static function inserirCliente($nome, $sobrenome) {
          $con = ConnectionFactory::getConnection();
          $stmt = $con->prepare("INSERT INTO pessoa(nome, sobrenome) VALUES(?, ?)");
          $stmt->bindParam(1, $nome);
          $stmt->bindParam(2, $sobrenome);
          $stmt->execute();
          $stmt->close();
          return;
         }
      }

pag_cadastro.php

    <?PHP
     // INCLUIR AQUI
    ?>
    <form action="#" method="post">
        <input type="text" name="nome" value="" />
        <input type="text" name="sobrenome" value="" />
        <input type="submit" value="Cadastrar" name="btn" />
    </form>

    <?php
        $nome = $_POST['nome'];
        $sobrenome = $_POST['sobrenome'];
        $verf = metodosPDO::inserirCliente($nome, $sobrenome);
    ?>

The folder structure looks like this:

Source files: PDO ~ > MetodosPDO.PHP / ConnectionFactory.php forms ~ > pag_cadastro.php

    
asked by anonymous 18.06.2018 / 04:05

0 answers