Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Does't work query to sqlite database in multi module app

Why can't work query to sqlite database in multi module app? Аlthough same query correctly work in single module app.


In registerServices section in Module:

        $di->set('db', function() {
            $config = array(
                'dbname' => realpath('../common/db/ece.sqlite')
            $db = new Phalcon\Db\Adapter\Pdo\Sqlite($config);
            return $db;

In Controller section:

        $users = $this->db->fetchAll('
            SELECT * FROM users 
            ORDER BY user_id, user_org, user_cab ASC', 
        $this->view->setVar('users', $users);       

App returns a clear page.


could you post please the relevant files to check what could be happening?

Try to define a root variable in your index.php as such

// Adjust this according to where the index.php is located
define('ROOT_PATH', dirname(dirname(__FILE__)));

and then you can use that in the 'dbname' to reference your db.

I have a feeling that switching through modules your db cannot be found. I could very well be wrong but that is where I would start.


@relort When I access http://localhost/test/db, the following message appears:

Fatal error: Class 'ECE\Frontend\Phalcon\Db\Adapter\Pdo\Sqlite' not found in /srv/www/htdocs/test/apps/frontend/Module.php on line 37

This happens due to the missing \ in front of Phalcon\Db\Adapter\Pdo\Sqlite on line 37. Fixing that I'm getting:

    [0] => stdClass Object
            [user_id] => 75
            [user_login] => Warehouse
            [user_password] => ###
            [user_role] => Guest
            [user_fio] => Склад
            [user_cab] => 0
            [user_dep] => 
            [user_pos] => 
            [user_tel] => 
            [user_ip] => 
            [user_compid] => 
            [user_org] => 


edited Oct '14

@Phalcon When i add \ in front of Phalcon\Db\Adapter\Pdo\Sqlite - It did not help. But then iadd \ in fron of "Phalcon\Db::FETCH_OBJ" in controller in query "$u = $this->db->fetchAll('SELECT * FROM users;', \Phalcon\Db::FETCH_OBJ)" and this help. Tnx a lot.