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!