使用Phalcon开发工具碰到的数据库问题"Table 'XXX' doesn't exist in database when dumping meta-data for XXX"

时间:2020-12-08 03:15:53

使用Phalcon开发工具,通过命令行生成程序框架

设置好config.php,在对数据库进行读取、保存数据的时候出现了问题“Table 'XXX' doesn't exist in database when dumping meta-data for XXX”

使用Phalcon开发工具碰到的数据库问题"Table 'XXX' doesn't exist in database when dumping meta-data for XXX"

注意到上方还有一条语句“Array to string conversion”,找到对应services.php处的代码

 $di->set('db', function () use ($config) {
return new DbAdapter($config->toArray());
});

再查看$config内容

$config = include __DIR__ . "/../app/config/config.php";

config.php内容

 <?php

 return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Mysql',
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'eduhelper',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'migrationsDir' => __DIR__ . '/../../app/migrations/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/eduHelper/',
)
));

经分析是数据库连接那块出了问题,可以看到$config中还有一个'application',而我们所需要的显然只有'database'

应该将services.php处的代码改为

 $di->set('db', function () use ($config) {
return new DbAdapter($config->database->toArray());
});

或者

$di->set('db', function () use ($config) {
return new DbAdapter($config['database']->toArray());
});