Pola private $zmienna to odpowiedniki nazw kolumn w tabeli, jak zrobić automat do deklaracji?
class User { public $id = ""; public $login = ""; public $passwd = ""; public $firstname = ""; public $lastname = ""; public $level = ""; public $user_id = 0; public $email = ""; public $mobile = ""; public $data_add = ""; public $username = ""; public function __construct(){} public function addUser(){} public function deleteUser(){} public function updateUser(){} }
Potem wypełniam taką klasę danymi już automatycznie w funkcji login():
class Authentication { private $db; public $user; public function __construct(){ $this->db = DBconnect::getInstance(); $this->user = new User; } public function get_param() { $this->user->login = $_POST["login"]; $this->user->passwd = $_POST["passwd"]; $_SESSION["login"] = $this->user->login; $_SESSION["passwd"] = $this->user->passwd; return true; $this->user->login = $_SESSION["login"]; $this->user->passwd = $_SESSION["passwd"]; return true; }else{ return false; } } public function login() { if( $this->get_param() ) { $sql = "select * FROM users WHERE active = 1 and login = :login and passwd = md5(:passwd)"; $query->bindParam(':login', $this->user->login, PDO::PARAM_STR); $query->bindParam(':passwd', $this->user->passwd, PDO::PARAM_STR); $query->execute(); if( $query->rowCount() > 0 ) { $column_data = $query->fetchAll(PDO::FETCH_ASSOC); foreach($column_data as $outer_key => $array){ foreach($array as $inner_key => $value){ $this->user->$inner_key = $value; } } }else{ $column_data = $query->fetchAll(PDO::FETCH_ASSOC); foreach($column_data as $outer_key => $array){ foreach($array as $inner_key => $value){ $this->user->$inner_key = ""; } } } } }