cdiego

php/puntosDAO.php

Jan 12th, 2014
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2. include_once 'conex.php';//INCLUIR CONEXION DE BASE DE DATOS
  3.  
  4. class puntosDao
  5. {
  6.     private $r;
  7.     public function __construct()
  8.     {
  9.         $this->r = array();
  10.     }
  11.     public function grabar($titulo, $cx,$cy)//METODO PARA GRABAR A LA BD
  12.     {
  13.         $con = conex::con();
  14.         $titulo = mysql_real_escape_string($titulo);
  15.         $cx = mysql_real_escape_string($cx);
  16.         $cy = mysql_real_escape_string($cy);
  17.         $q = "insert into puntos (Titulo, cx, cy)".
  18.              "values ('".addslashes($titulo)."','".addslashes($cx)."','".addslashes($cy)."')";
  19.         $rpta = mysql_query($q, $con);
  20.         mysql_close($con);
  21.         if($rpta==1)
  22.         {
  23.             return TRUE;
  24.         }
  25.         else
  26.         {
  27.             return FALSE;
  28.         }
  29.     }
  30.     public function listar_todo()
  31.     {
  32.         $q = "select * from puntos";
  33.         $con = conex::con();
  34.         $rpta = mysql_query($q,$con);
  35.         mysql_close($con);
  36.         while($fila = mysql_fetch_assoc($rpta))
  37.         {
  38.             $this->r[] = $fila;
  39.         }
  40.         return $this->r;
  41.     }
  42.     public function borrar($idPunto)//METODO PARA BORRAR DE LA BD
  43.     {
  44.         $con = conex::con();
  45.         $idPunto = mysql_real_escape_string($idPunto);
  46.         $q = "delete from puntos where IdPunto = ".(int)$idPunto;
  47.         $rpta = mysql_query($q, $con);
  48.         mysql_close($con);
  49.         if($rpta==1)
  50.         {
  51.             return TRUE;
  52.         }
  53.         else
  54.         {
  55.             return FALSE;
  56.         }
  57.     }
  58.     public function actualizar($Id, $titulo, $cx,$cy)//METODO PARA ACTUALIZAR A LA BD
  59.     {
  60.         $con = conex::con();
  61.         $Id = mysql_real_escape_string($Id);
  62.         $titulo = mysql_real_escape_string($titulo);
  63.         $cx = mysql_real_escape_string($cx);
  64.         $cy = mysql_real_escape_string($cy);
  65.         $q = "update puntos set Titulo='".$titulo."', cx='".$cx."' , cy ='".$cy."' where IdPunto =".$Id;
  66.         $rpta = mysql_query($q, $con);
  67.         mysql_close($con);
  68.         if($rpta==1)
  69.         {
  70.             return TRUE;
  71.         }
  72.         else
  73.         {
  74.             return FALSE;
  75.         }
  76.     }
  77. }
  78. ?>
Advertisement
Add Comment
Please, Sign In to add comment