I've just begun creating a class to get User information, and I'd like for it to be improved.
The global variable $oConni
is the database connection.
class UserInfo {
public $id, $oConni;
public function __construct($id, $oConni) {
$this->id = $id;
$this->oConni = $oConni;
}
public function getInfo() {
$userInfo = array();
$cSQL = "SELECT name, last_name, email, use_gravatar, pic_profile FROM users WHERE id = ?";
$stmt = $this->$oConni->prepare($cSQL);
$stmt->bind_param('i', $this->$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($name, $lastName, $email, $gravatar, $picProfile, $admin);
if ($stmt->fetch()) {
$userInfo['name'] = $name;
$userInfo['lastName'] = $lastName;
$userInfo['email'] = $email;
$userInfo['gravatar'] = $gravatar;
if($gravatar == 1){
$size = 500;
$grav_url = "http://www.gravatar.com/avatar/".md5(strtolower(trim($email)))."?s=" . $size;
$userInfo['picProfile'] = $grav_url;
}else if(strpos($picProfile, 'http') === 0 || strpos($picProfile, 'https') === 0){
$userInfo['picProfile'] = $picProfile;
}else{
$pic = 'http://www.example.com/'.$picProfile.'?id='.RAND(0,999999);
$userInfo['picProfile'] = $pic;
}
}
$stmt->close();
return $userInfo;
}
}
$userInf = new UserInfo($cmntUser, $oConni);
$userData = $userInf->getInfo();
print_r($userData);