Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/05/2013, 04:56
XD2XD2
 
Fecha de Ingreso: diciembre-2012
Mensajes: 223
Antigüedad: 11 años, 4 meses
Puntos: 2
Opinar Sobre esta CLASS

Estoy haciendo un acortador de URL y voy hacer esta class para hacer las consultas.
¿Es recomendable utilizarla?¿Se puede mejorar?¿Como?

Código PHP:
<?php
class AcortarURL
{
    
    public function 
__construct()
    {
        
$this->host '.......';
        
$this->user '.......';
        
$this->pass '.....';
        
$this->db '...........';
        
$this->connect mysqli_connect($this->host,$this->user,$this->pass,$this->db);
    }
    
    public function 
Query($sql,$camp)
    {
        
$this->Query mysqli_fetch_assoc(mysqli_query($this->connect,$sql));
        if(
$this->Query):
            return 
$this->Query[$camp];
        else:
            echo 
'No existe';
        endif;
        return 
$this->Query;
    }
    
    public function 
Select($sql)
    {
        
$this->Select mysqli_query($this->connect,$sql);
        return 
$this->Select;
    }
}

$MySQL = new AcortarURL();

// Ejemplos
$MySQL->Query("SELECT * FROM url WHERE id = '1'"'id'); // Eligo el campo, y compruebo si existe o no.
if($MySQL->Query['id'] == 'noseque'): // Hago un if, y muestro si el contenido es correcto o no.
    
echo 'Correcto';
else:
    echo 
'Incorrecto';
endif;

$MySQL->Select("SELECT * FROM url"); // Hago la consulta.
while($MySQL->Select1 mysqli_fetch_assoc($MySQL->Select)){ // Hago el while.
    
echo $MySQL->Select1['id']; // Muestro el campo.
}
?>

Última edición por XD2XD2; 18/05/2013 a las 05:58