mysqli_fetch_assoc创建无限循环

时间:2013-06-08 10:45:55

标签: php mysqli

我不知道为什么,但是mysqli_fetch_assoc创造了一个无限循环。

谁能明白为什么?


页面控制器

class EditChargesTypePageController extends PageController {
    protected function execute () {
        parent::execute();

        // Infinite Loop
        while ($chargesType = mysqli_fetch_assoc(DataManager::sharedInstance()->chargesTypes())) {
            print_r($chargesType);
        }

        $this->_templateName = "./charges/editChargesType.html";
        $this->_viewBag['title'] = "Login";
    }
}

数据管理器

class DataManager extends Singleton {
    private $db;

    function __construct () {
        $this->db = new DBManager(kDBHost, kDBUser, kDBPassword, kDBDatabase);
    }

    public function chargesTypes () {
        return mysqli_query(
            $this->db->connection(),
            "SELECT * FROM " . DBManager::kTableChargesType
        );
    }

};

数据库管理员

class DBManager {
    private $connection;

    // Default Database
    private static $defaultDBManager;

    public static function defaultDBManager() {
        if (self::$defaultDBManager == null) {
            self::$defaultDBManager = new ITDBManager(kDBHost, kDBUser, kDBPassword, kDBDatabase);
        }

        return self::$defaultDBManager;
    }

    function __construct ($host, $username, $password, $db) {
        $this->connection = mysqli_connect($host, $username, $password, $db);
    }

    function connection() {
        return $this->connection;
    }
}

1 个答案:

答案 0 :(得分:1)

我认为问题在于DataManager::sharedInstance()->chargesTypes()不断返回新资源。