0
votes

Need help using Zend\Db\Sql\Select. Can't figure out what I'm doing wrong, it outputs nothing and no errors displayed.

namespace Album\Model;
use Zend\Db\Adapter\Adapter,
    Zend\Db\Sql\Select;

class AlbumTable
{
    public function getAll()
    {
        $select = new Select('album'); 
        return $select->from();
    }
}

namespace Album\Controller;

class AlbumController extends AbstractActionController
{
    public function indexAction()
    {
        return new Viewmodel(array(
            'rows' => $this->albumTable->useSelect()
        ));
    }
}

// index.phtml
foreach ($this->rows as $row) { echo $row->artist . '<br />'; }

Thanks

1
You might want to turn on error reporting and display errors in your php configuration to help with resolving errors. For one you are calling an AlbumTable method from your controller which does not exist. It seems you have no Db adapter setup either. I highly recomend running through the getting started guide where all this is explained in great detail. - Aydin Hassan
Where is this method $this->albumTable->useSelect() coming from? - Stoyan Dimov
Thanks Stoyan & Aydin. I got it working now - Ori

1 Answers

1
votes

Figured I didn't query the string I built.

Zend\Db\Sql\Sql; 

class AlbumTable
{
    public function getAll()
    {
        $sql = new Sql($this->adapter);
        $select = new Select('album');

        $selectString = $sql->getSqlStringForSqlObject($select);
        return $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
    }
}