Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/11/2012, 06:30
oliverf2
 
Fecha de Ingreso: octubre-2012
Ubicación: Austria
Mensajes: 47
Antigüedad: 11 años, 6 meses
Puntos: 7
Respuesta: Opinion sobre mis primeras clases POO

Hola de nuevo, si te he entendido bien te refieres a esto?

Clase
Código PHP:
class validations {
    private 
$user;
    private 
$password;
    private 
$db;

    public function 
__construct($user,$password) {
        
$this->user $user;
        
$this->password $password;
    }

    public function 
set_db($db) {
        
$this->db $db;
    }
    public function 
validateuser() {
        if(!isset(
$this->db)) { 
            throw new 
Exception('You have to call method set_db before!');

        } else {
            
$stmt $this->db->prepare("select * from USER where 
                USERNAME = '"  
mysqli_real_escape_string($this->db,$this->user) . "'
                AND PASSWORD = '" 
mysqli_real_escape_string($this->db,MD5($this->password)) ."'");
            
$stmt->execute();
            
$result $stmt->store_result();

            if ((
$stmt->num_rows) > 0
            { 
                return 
true;
                
$stmt->free_result();
            }else {
                return 
false;
                
$stmt->free_result();

            }
        }
    }


Código PHP:
$conexion = new mysqli($dbhost,$dbuser,$dbpassword,$database);
$nuevavalidacion = new validations("oliver","oliver");
$nuevavalidacion->set_db($conexion);
$nuevavalidacion->validateuser(); 
Muchas gracias de nuevo por tu ayuda, no sabes cuanto te lo agradezco

Un saludo!