1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
class DB
{
...
function &getInstance()
{
static $_db_singleInstance = null;
if(!is_object($_db_singleInstance))
$_db_singleInstance =& new DB();
return $_db_singleInstance;
}
function numRows($result = '')
{
if(empty($result))
$result = $this->dbResult;
return mysql_num_rows($result);
}
function fetch($result = '',$object = false)
{
if(empty($result))
$result = $this->dbResult;
if ($object)
return mysql_fetch_object($result);
else
return mysql_fetch_array($result, MYSQL_ASSOC);
}
...
}
class Account
{
var $_userInfos;
var $_db;
function Account($uid = false)
{
$this->_db = DB::getInstance();
$this->resetInfos();
if ($uid !== false)
$this->load($uid);
}
function resetInfos()
{
$this->_userInfos = array(
'uid' => 0,
'login' => '',
'mail' => '',
'pass' => '',
'country' => '',
'city' => '',
'lastseen' => '',
'ip' => ''
);
}
function load($uid)
{
$this->_db->query('SELECT * FROM '.TBL_ACCOUNT.' WHERE uid='.(int)$uid);
if($this->_db->numRows() == 0)
{
$this->resetInfos();
return false;
}
foreach($this->fetch() as $info => $value)
$this->setInfo($info,$value);
return true;
}
function setInfo($info,$value)
{
if(!isset($this->_userInfos[$info]))
return false;
$this->_userInfos[$info] = $value;
return true;
}
}
$account = new Account(0);
echo $account->login.' from '.$account->country;
|
Partager