Created
November 9, 2017 17:00
-
-
Save jeffersonchaves/4fd630a0853424a3c5c0998ada49d858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "../conexao/Conexao.php"; | |
class Produto { | |
private $codigo; | |
private $titulo; | |
private $preco; | |
private $categoria; | |
private $conexao; | |
public function __construct($titulo, $preco, $categoria) { | |
$this->titulo = $titulo; | |
$this->preco = $preco; | |
$this->categoria = $categoria; | |
$con = new Conexao(); | |
$this->conexao = $con->getConexao(); | |
} | |
public function cadastrar(){ | |
$sql = "INSERT INTO tb_produtos (titulo, preco, categoria) VALUES ('$this->titulo', $this->preco, '$this->categoria')"; | |
$this->conexao->exec($sql); | |
} | |
public function getProdutos(){ | |
$this->conexao->query("SELECT * FROM tb_produtos"); | |
return $consulta->fetchAll(PDO::FETCH_ASSOC); | |
} | |
} | |
//teste | |
$produto = new Produto("Lorem Ipsum", 9.99, "lorem"); | |
$produto->cadastrar(); | |
$lista = $produto->getProdutos(); | |
print_r($lista); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment