Advertisement
Ivan_sjc

PHP Orientado

Feb 7th, 2015
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.35 KB | None | 0 0
  1. ******************************************************************************Arquivo conexão.class.php
  2. <?php
  3.  
  4. <?php
  5. class Database
  6. {
  7.  
  8.     // specify your own database credentials
  9.     private $host = "127.0.0.1";
  10.     private $db_name = "sisim";
  11.     private $username = "root";
  12.     private $password = "";
  13.     public $conn;
  14.  
  15.     // get the database connection
  16.     public function getConnection()
  17.     {
  18.  
  19.         $this->conn = null;
  20.  
  21.         try {
  22.             $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
  23.         } catch (PDOException $exception) {
  24.             echo "Connection error: " . $exception->getMessage();
  25.         }
  26.  
  27.         return $this->conn;
  28.     }
  29. }
  30. ?>
  31.  
  32. ************************************************************************************************Arquivo.class.php
  33.  
  34.  
  35. <?php
  36.    
  37.     class EmpresaDAO{
  38.    
  39.    
  40.    
  41.     private $conn;
  42.     private $table
  43.     private $table_name = "cadastro_emp";
  44.    
  45.    
  46.    
  47.     public function __construct($db)
  48.     {
  49.         $this->conn = $db;
  50.     }
  51.  
  52.  
  53.    
  54.    
  55.      public function createEmpresa($razao_social,$cnpj,$inscricao_estadual)[{
  56.     {
  57.         //write query
  58.         $query = "INSERT INTO " . $this->table_name . " (`razao_social`,`cnpj`,`inscricao_estadual`) VALUES (?,?,?)";
  59.         echo "$query";
  60.        
  61.         $stmt = $this->conn->prepare($query);
  62.  
  63.         $stmt->bindParam(1,($razao_social);
  64.         $stmt->bindParam(2, $this->$cnpj);
  65.         $stmt->bindParam(3, $this-$inscricao_estadual);
  66.  
  67.         if ($stmt->execute()) {
  68.             return true;
  69.         } else {
  70.             return false;
  71.         }
  72.  
  73.     }
  74.  
  75.    
  76.    
  77.     }
  78.  
  79.  
  80.  
  81.  
  82. ?>
  83. ************************************************************************************************ arquivo EmpresaController.php
  84.  
  85. <?php
  86.  
  87.     if ($_SERVER['REQUEST_METHOD']=='POST'){
  88.        
  89.         $database = new Database();
  90.         $empresaDAO = new EmpresaDAO($database->getConnection());
  91.         $empresa = new Empresa();
  92.        
  93.         $empresa.razao_social ->  $_POST['razaosocial'];
  94.         $empresa.cpf -> $_POST['cpf'];
  95.         $empresa.inscricao_estadual-> $_POST['inscricao_estadual'];
  96.        
  97.         $empresaDAO->createEmpresa($empresa.razao_social,empresa.cpf,empresa.inscricao_estadual);
  98.        
  99.     }
  100.     ?>
  101.  
  102. e meu forme do html que nao vejo necessidade de colocar se nao só vai ocupar espaço o meu form ta enviar os dados pro controller :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement