【发布时间】:2015-04-16 12:02:12
【问题描述】:
Phalcon 无法连接到 postgrsql。这是我在 config.php 中的设置
return new \Phalcon\Config(array(
'database' => array(
'adapter' => 'Postgresql',
'host' => 'localhost',
'username' => 'postgres',
'password' => 'root',
'dbname' => 'mydb',
'charset' => 'utf8',
),
'application' => array(
'controllersDir' => __DIR__ . '/../../app/controllers/',
'modelsDir' => __DIR__ . '/../../app/models/',
'viewsDir' => __DIR__ . '/../../app/views/',
'pluginsDir' => __DIR__ . '/../../app/plugins/',
'libraryDir' => __DIR__ . '/../../app/library/',
'cacheDir' => __DIR__ . '/../../app/cache/',
'baseUri' => '/test/',
)
));
页面是空白的,没有错误。
DI服务实现
use Phalcon\Db\Adapter\Pdo\Postgresql as DbAdapter;
$di->set('db', function () use ($config) {
return new DbAdapter(array(
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname,
"charset" => $config->database->charset
));
});
【问题讨论】:
-
您是否收到任何错误消息?
-
好的,但配置还不够。给我们您的
$di->db服务实施和使用案例。至少也应该显示一些错误。 -
在 index.php 中添加
ini_set('display_errors', 1);。您还需要将 DbAdapter 更改为Phalcon\Db\Adapter\Pdo\Postgresql。我们还需要了解您的服务是如何设置的。 -
使用 phalcon 调试器(在 public/index.php 中没有 try-catch)并向我们显示错误。
标签: postgresql phalcon