0

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

3
  • 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. Commented Mar 16, 2013 at 16:15
  • Where is this method $this->albumTable->useSelect() coming from? Commented Mar 17, 2013 at 11:02
  • Thanks Stoyan & Aydin. I got it working now Commented Mar 21, 2013 at 3:12

1 Answer 1

1

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);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.