> I think there is a feature request in there though. Perhaps the Sql
object could have an execute() which would be similar in nature to
Zend\Db\Adapter\Adapter::query(). The downside is that you are throwing
away the statement produced in favor of just the result. While that may
seem like what you're really after in most cases, this also means you
cannot change a parameter in the ParameterContainer and then execute
(again) and already prepared statement.
>
> I will see about this. It would look more like this though (just
stabbing in the dark):
>
> $select = $table->getSql()->select();
> $select->columns(['count' => new Expr('count(id)')]);
> $results = $table->getSql()->execute($select);
>
> var_dump($results->toArray());
Something like that would be perfect. It's nice and simple to understand
and means that if you just want to get the database result you can bypass
the extra steps.
Thanks,
~Stephen
On 10 November 2012 01:48, Ralph Schindler <[email protected]> wrote:
>
> 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?
>>
>
> On the select object, probably not. The Select object by itself does not
> do SQL abstraction, only when prepared with a Sql object will you get SQL
> abstraction. The Select by itself will produce ANSI-compatible-ish
> queries, specific to the adapter and the platform.
>
> I think there is a feature request in there though. Perhaps the Sql
> object could have an execute() which would be similar in nature to
> Zend\Db\Adapter\Adapter::**query(). The downside is that you are
> throwing away the statement produced in favor of just the result. While
> that may seem like what you're really after in most cases, this also means
> you cannot change a parameter in the ParameterContainer and then execute
> (again) and already prepared statement.
>
>
> 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 will see about this. It would look more like this though (just stabbing
> in the dark):
>
> $select = $table->getSql()->select();
> $select->columns(['count' => new Expr('count(id)')]);
> $results = $table->getSql()->execute($**select);
>
> var_dump($results->toArray());
>
> -ralph
>
> --
> List: [email protected]
> Info: http://framework.zend.com/**archives<http://framework.zend.com/archives>
> Unsubscribe:
> fw-general-unsubscribe@lists.**zend.com<[email protected]>
>
>
>
--
Stephen Rees-Carter ~ Valorin
http://stephen.rees-carter.net/