require_once 'DB.php';
class pc_user {
var $data = array();
function pc_user($user) {
/* connect to database and load information on
* the user named $user into $this->data
*/
$dsn = 'mysql://user:password@localhost/test';
$dbh = DB::connect($dsn);
if (DB::isError($dbh)) { die ($dbh->getMessage()); }
$user = $dbh->quote($user);
$sql = "SELECT name,email,age,gender FROM users WHERE user LIKE '$user'";
if ($data = $dbh->getAssoc($sql)) {
foreach($data as $key => $value) {
$this->data[$key] = $value;
}
}
}
function __get($property_name, &$property_value) {
if (isset($this->data[$property_name])) {
$property_value = $this->data[$property_name];
return true;
}
return false;
}
function __set($property_name, $property_value) {
$this->data[$property_name] = $property_value;
return true;
}
}