从程序样式和MySQLi切换到OOP

时间:2015-05-12 16:44:04

标签: php oop mysqli

如何扩展/包含执行某些数据库查询的另一个类?

在方法" getAccount"中,我想在课堂上调用某个方法" UserQueries"这将发回一组用户数据。

在搬到OOP时,我也应该问一下;每种类型的mysqli交互都应该有一个类吗?

现在(程序)我有一个名为" functions.php"的文件。它变得非常庞大和粗糙。

class AccountManager {

private $type = ""; //user type
private $id = 0; //user id

private $user; //array of users info
private $tmpID; //tmpID that is sent in

public $success;

public function __construct($uid) {
    //passed in userID
    $this->tmpID = $uid;
    $this->success = null;
    self::getAccount();
}

public function __destruct() {
}

protected function getAccount() {
    //$this->user = UserQueries::get_user_by_id($this->tmpID);
    //get_user_by_id will return an array
    //Example of what would be returned
    $this->user = ["1", 'someuser', "101"];
    if($this->user) {
        $this->success = self::setAccount();
    } else {
        $this->success = false;
    }
}

private function setAccount() { ....
//more logic
}
}

感谢。

0 个答案:

没有答案