We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

ORM object has not access to database

Hi everybody,

please help me to resolve some problem related to my project.

I have created model class Users extends from \Phalcon\Mvc\Model. After i make a simple select query and get the follow error "SQLSTATE[28000] [1045] Access denied for user 'postgres'@'localhost' (using password: YES)" the sample code: $users = new Users(); $result = $users::query()->execute()->toArray();

But when i create connect to database via php core function pg_connect, all works right the sample code: pg_connect("host=localhost dbname=admin_paybox user=postgres password=admin"); $query = <<<SQL select * from users; SQL; $result = pg_query($query);



3.3k

Can you cut/paste your "db" service



755

return new \Phalcon\Config(array( 'database' => array( 'adapter' => 'Postgresql', 'host' => 'localhost', 'username' => 'postgres', 'password' => 'admin', 'dbname' => 'admin_paybox', 'schema' => 'public' ) )

$di = new FactoryDefault();

$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 )); });

Can you cut/paste your "db" service



755
Accepted
answer

I have found the resolving the problem. For Postgresql need to use \Phalcon\Db\Adapter\Pdo\Postgresql, instead DbAdapter in service. DbAdapter is used only for Mysql