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

setting @var before SELECT in Raw SQL

my query is same as this:

SET @increment := 1;  
SELECT @increment := @increment + 1, username from aTable  

but I receive an error because "SET @increment := 1;" is before SELECT query:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error

my query is working on PHPMyAdmin.

How u execute that query? Try this way (or other with that kind of query execution):

                $query = "  SET @increment := 1;  
                                    SELECT @increment := @increment + 1, username from aTable
                ";
                \Phalcon\Di::getDefault()->getDb()->query($query);

did you mean indentation will fix it?!!

I'm using PDO mysql Adapter:


$data = $this->db->query($queryString);
$data->setFetchMode(\Phalcon\Db::FETCH_OBJ);
$rankedUsers = $data->fetchAll();