我不知道为什么,但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;
}
}