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

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.

Code:

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', 
            Phalcon\Db::FETCH_OBJ
        );
        $this->view->setVar('users', $users);       

App returns a clear page.



98.9k

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.



98.9k

@relort When I access https://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:

frontend:
Array
(
    [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] => 
        )

)


5.5k
Accepted
answer
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.