Hi all,
Someone please correct me if I've missed the easy way to do this!
Currently to build a manual SQL statement and execute it, it takes a couple
of extra steps which I don't understand or see the need for. For example,
let's run this query: SELECT count(id) AS `count` FROM `affected_version`
$sql = $table->getSql();
$select = $sql->select()->columns(Array('count' => new
Expr('count(id)')));
$statement = $sql->prepareStatementForSqlObject($select);
$results = $statement->execute();
foreach ($results as $value) {
\Zend\Debug\Debug::dump($value);
}
The first two lines make sense.
The third and forth lines (prepare*() & execute()) seem needlessly verbose.
Can't it be simplified down into a single "execute() function on the Select
object?
Finally, I get back some weird Result object which I need to do yet another
operation on before I can even access the query data in a useful way.
Again, it seems needlessly verbose and not very useful. ZF1 made this
pretty easy from memory.
I personally would love to write code like this:
$sql = $table->getSql();
$select = $sql->select()->columns(Array('count' => new
Expr('count(id)')));
$results = $select->execute();
\Zend\Debug\Debug::dump($results);
I'm sure there is a very good reason for this... But I don't have a clue
what it is.
Can anyone help me out here?
Thanks,
~Stephen
--
Stephen Rees-Carter ~ Valorin
http://stephen.rees-carter.net/