Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Arquivo Contatos.class.php
- Irá criar uma classe chamada Contatos que terá como atributos
- nome, email e telefone
- */
- class Contatos {
- //criação dos atributos
- private $idContato;
- private $nome;
- private $telefone;
- private $email;
- /*criação do método construtor
- é chamado ao criar new (parametros)
- */
- public function __construct($nome,$telefone,$email){
- $this->nome=$nome;
- $this->telefone=$telefone;
- $this->email=$email;
- }
- public function getIdContato(){
- return $this->idContato;
- }
- public function setIdContato($idContato){
- $this->idContato = $idContato;
- }
- public function getNome(){
- return $this->nome;
- }
- public function setNome($nome){
- $this->nome = $nome;
- }
- public function getTelefone(){
- return $this->telefone;
- }
- public function setTelefone($telefone){
- $this->telefone = $telefone;
- }
- public function getEmail(){
- return $this->email;
- }
- public function setEmail($email){
- $this->email = $email;
- }
- public function salvarDados() {
- include "acessa.php";
- $nome = $this->nome;
- $telefone = $this->telefone;
- $email = $this->email;
- $sql="INSERT INTO contatos (id, nome,telefone,email)
- VALUES ('','$nome','$telefone','$email')";
- if($conexao->query($sql) === false) {
- trigger_error('Erro na SQL: '.$sql.' Erro: '.
- $conexao->error, E_USER_ERROR);
- }
- else {
- echo "Cadastro de novo contato efetuado com sucesso";
- return $conexao->insert_id;
- }
- $conexao->close();
- }
- public function imprimeDados($id){
- include "acessa.php";
- $sql = "Select * from contatos where id = $id";
- if(!$resultado = $conexao->query($sql)) {
- trigger_error('Erro na SQL: ' . $sql . ' Erro: ' .
- $conexao->error, E_USER_ERROR);
- }
- else {
- //vamos listar o cadastro do banco
- while($linha = $resultado->fetch_assoc()) {
- $this->id=$linha["id"];
- $this->nome=$linha["nome"];
- $this->telefone=$linha["telefone"];
- $this->email=$linha["email"];
- }
- }
- $conexao->close();
- }
- }
- /*
- CREATE TABLE IF NOT EXISTS `contatos` (
- `id` int(11) NOT NULL,
- `nome` varchar(200) NOT NULL,
- `telefone` varchar(50) NOT NULL,
- `email` varchar(100) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment