Use of the return value of StatementInterface::execute()

Hi i am having some trouble in a part to retrieve data from my database in order set a multi-language application, where i would on app start to redirect to the default language that i have predefined as a column as of type Bool/TinyINT, but as I connect and try to execute a statement to retrieve all the languages list in my database table it won’t return the results. Can someone help me here? Here is my class.

namespace Nanocord\Mvc;

// Load classes
use Laminas\Mvc\Application as LaminasApplication;
use Laminas\Db\Adapter\Adapter;
use Laminas\Db\Sql\Sql;

 * Application
 * @category    Nanocord
 * @package     Mvc
 * @subpackage  Application
class Application extends LaminasApplication 
    private $config;
    private $db;
    private $isConnected;
    private $sql;
    public function __construct($config) 
        $this->config = $config;

    public function start() 
        $application = parent::init($this->config)->run();
        $db_config = $application->getConfig()['db'];
        $db_adapter = new Adapter($db_config);
        if ($db_adapter->driver->getConnection()->isConnected() === true) {
            $this->db = $db_adapter;
            $this->isConnected = true;
            $this->sql = new Sql($this->db);
    public function initLanguage() 
        $select = $this->sql->select();
        $statement = $this->sql->prepareStatementForSqlObject($select);
        $results = $statement->execute();
    public function initSession() 


Are you expecting $results to contain the results from the query? If so, you are missing a few steps.

$statement->execute() returns a ResultSet and not an array of data rows.

ResultSet allows you to iterate through the rows returned by your query.

// To get the current row

// Then go to the next row

// ResultSet are Iterators, use this to iterate through each row
foreach($results as $result) {
   // do something with $results as it contains the data from the row

Check out the ResultSet documentation in the laminas-db component documentation.

I hope that I got your question right and this answers it.

Yes looping the results works but I thought by dumping the statement execuet would also give me an idea of what it would give out as an output

Not quite.

I never looked under the hood but I would think that this is an elaboratd abstraction of PHP’s PDOStatement::execute which does not return data until you call PDOStatement::fetch.

Somewhere within ResultSet, when you call the count() or current() or iterate through ir, the PDOStatement::fetch gets called.

The MVC component is event driven and therefore you can use a listener which is listen to one of the existing MVC events. In the listener you can execute your code.
This allows to define when your code will be executed (listener is triggered) and you can access the servicemanager of your application (to get the database adapter or something else).

Some examples can be found in the documentation or here in the forum.

One of the examples:

You marked this thread as solved therefore please open new thread if you have a new question. Otherwise the overview is lost.
Thanks in advance!