Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class crud {
- public $tabela;
- public function _construct($tabela){
- $this->tabela = $tabela;
- }
- public function inserir($nome,$fone){
- $sql = "INSERT INTO".$this->tabela."(nome,fone) values(".$nome."','".$fone."')";
- $ok = mysql_query($sql);
- if(!$ok){
- die("Erro na inserção:".mysql_error());
- }
- else {
- Echo "<script>alert('Sucesso na operação!')</script>";
- }
- }
- public function editar($nome,$fone, $id){
- $sql = "UPDATE".$this->tabela."SET nome='".$nome."', fone='".$fone."' WHERE id=".$id;
- $ok = mysql_query($sql);
- if(!$ok){
- die("Erro na atualização:".mysql_error());
- }
- else {
- Echo "<script>alert('Sucesso na atualização!')</script>";
- }
- }
- public function deletar ($id){
- $sql = "DELETE".$this->tabela." WHERE id=".$id;
- $ok = mysql_query($sql);
- if(!$ok){
- die("Erro na exclusão:".mysql_error());
- }
- else {
- Echo "<script>alert('Sucesso na eclusão!')</script>";
- }
- }
- public function selecionaId ($id){
- $sql = "SELECT * FROM".$this->tabela." WHERE id=".$id;
- $ok = mysql_query($sql);
- if(!ok){
- die("Erro na seleção por ID:".mysql_error());
- }
- else {
- return $ok;
- }
- }
- public function selecionaTodos(){
- $sql = "SELECT * FROM".$this->tabela;
- $ok = mysql_query($sql);
- if(!$ok){
- die("Erro na seleção dos registros:".mysql_error());
- }
- else {
- return $ok;
- }
- }
- public function contaRegistros(){
- $sql = "SELECT COUNT(*) AS num_linhas FROM".$this->tabela;
- $ok = mysql_query($sql);
- if(!$ok){
- die("Erro na contagem de todos os registros:".mysql_error());
- }
- else {
- return $ok;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement