PHP Swiftlet mysqli error


PHP Swiftlet mysqli error

错误:

致命错误:Swiftlet''App::autoload

我是MVC的新手,正在试用Swiftlet。我正在尝试建立一个MYSQL数据库模型。

我已将错误确定为:

class Database extends 'Swiftlet'Model {
    public $mysqli;
    public function __construct(App $app) {
        $this->mysqli = new mysqli($this->app->getConfig('dbHost'),
                                   $this->app->getConfig('dbUser'),
                                   $this->app->getConfig('dbPassword'),
                                   $this->app->getConfig('dbName'));
    }
}

但我不知道为什么。为什么要尝试加载mysqli

问题似乎出在'Swiftlet命名空间中。当试图从这个名称空间中实例化mysqli(全局命名空间中的一个项)时,它正在尝试自动加载它通常会在其命名空间中自动加载类的地方。该类不存在,因此会出现自动加载错误。

试着这样更改你的mysqli实例化:

$this->mysqli = new 'mysqli($this->app->getConfig('dbHost'), $this->app->getConfig('dbUser'), $this->app->getConfig('dbPassword'), $this->app->getConfig('dbName'));

注意,myslqi现在以'为前缀,从而引用全局命名空间中的mysql类。