0

I have the following statements but they return an empty result set:

    $sql = 'SELECT * FROM `industry` WHERE `code` LIKE ?';
    $statement = $this->getAdapter()->createStatement($sql, array('A_'));
    $statement->execute();

What am I doing wrong? I really don't want to use the Zend\Db\Sql\Sql, as it is very verbose.

On a related point, where can I go to find out more about the theory of operation for Zend\Db? It's absolutely maddening. Why does it sometimes return a driver result? Sometimes a ResultSet? How can you view the complete SQL (after quoting, but before execution?) Etc...

DatsunBing
  • 8,684
  • 17
  • 87
  • 172

2 Answers2

0

OK, I had missed the fact that a Result is iterable (as well as a ResultSet). Therefore, assigning the result of $statement->execute() to a variable, then iterating that variable, sorted out the problem.

Futhermore, you can call getResource() on the result object, and from there access the underlying object (in this case, a PDO Statement). This means you can do things like result->getResource()->fetchAll();

DatsunBing
  • 8,684
  • 17
  • 87
  • 172
0

Try with this query.

use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql\Sql;

    class tableNameTable
    {

        protected $tableGateway;

        public function __construct(TableGateway $tableGateway)
        {
            $this->tableGateway = $tableGateway;
        }

        Publice function getIndustry(){
            $adapter = $this->tableGateway->getAdapter();
            $statement = $adapter->query("Your Query");
            $results = $statement->execute();

            return $results;
       }

    }
UWU_SANDUN
  • 1,123
  • 13
  • 19