Advertisement
DesenvolverBatch

crud.class.php

Oct 27th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2. class crud {
  3.     public $tabela;
  4.    
  5.     public function _construct($tabela){
  6.        $this->tabela = $tabela;
  7.     }
  8.  
  9.     public function inserir($nome,$fone){
  10.         $sql = "INSERT INTO".$this->tabela."(nome,fone) values(".$nome."','".$fone."')";
  11.         $ok = mysql_query($sql);
  12.         if(!$ok){
  13.             die("Erro na inserção:".mysql_error());
  14.         }
  15.         else {
  16.             Echo "<script>alert('Sucesso na operação!')</script>";
  17.         }
  18.     }
  19.  
  20.     public function editar($nome,$fone, $id){
  21.         $sql = "UPDATE".$this->tabela."SET nome='".$nome."', fone='".$fone."' WHERE id=".$id;
  22.         $ok = mysql_query($sql);
  23.         if(!$ok){
  24.             die("Erro na atualização:".mysql_error());
  25.         }
  26.         else {
  27.             Echo "<script>alert('Sucesso na atualização!')</script>";
  28.         }
  29.     }
  30.  
  31.     public function deletar ($id){
  32.         $sql = "DELETE".$this->tabela." WHERE id=".$id;
  33.         $ok = mysql_query($sql);
  34.         if(!$ok){
  35.             die("Erro na exclusão:".mysql_error());
  36.         }
  37.         else {
  38.             Echo "<script>alert('Sucesso na eclusão!')</script>";
  39.         }
  40.     }
  41.  
  42.     public function selecionaId ($id){
  43.         $sql = "SELECT * FROM".$this->tabela." WHERE id=".$id;
  44.         $ok = mysql_query($sql);
  45.         if(!ok){
  46.             die("Erro na seleção por ID:".mysql_error());
  47.         }
  48.         else {
  49.             return $ok;
  50.         }
  51.     }
  52.  
  53.     public function selecionaTodos(){
  54.         $sql = "SELECT * FROM".$this->tabela;
  55.         $ok = mysql_query($sql);
  56.         if(!$ok){
  57.             die("Erro na seleção dos registros:".mysql_error());
  58.         }
  59.         else {
  60.             return $ok;
  61.         }
  62.     }
  63.  
  64.     public function contaRegistros(){
  65.         $sql = "SELECT COUNT(*) AS num_linhas FROM".$this->tabela;
  66.         $ok = mysql_query($sql);
  67.         if(!$ok){
  68.             die("Erro na contagem de todos os registros:".mysql_error());
  69.         }
  70.         else {
  71.             return $ok;
  72.         }
  73.     }
  74.  }
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement