2008年12月3日星期三

Re: [fw-db] Zend_Db::insertSelect() / INSERT INTO ... SELECT ?

DO you by chance know the availability of this SQL syntax across the board
of RMDBS? Which RMDBS are you using?

-ralph


On 12/3/08 6:08 PM, "Stephan Wentz" <stephan@wentz.it> wrote:

> Is there a method like this planned in Zend_Db?
>
> Would be great, and isn't too hard. Something like
>
> public function insertSelect($tableName, Zend_Db_Select $select, array
> $fields = array()) {
> $fieldString = '';
> if (count($fields))
> {
> foreach($fields as $fieldKey => $field)
> {
> $fields[$fieldKey] = $this->quoteIdentifier($field);
> }
>
> $fieldString = ' (' . implode(',', $fields) . ')';
> }
>
> $query = "INSERT INTO ".$this->quoteIdentifier($tableName) .
> $fieldString . " ";
> $query .= $select;
>
> $this->_db->query($query);
> }
>
> I have several places in my app that need an INSERT INTO ... SELECT
> statement, right this is the only place where I haven't got database
> independent code...
>
> Bye,
> Stephan
>

--
Ralph Schindler
Software Engineer | ralph.schindler@zend.com
Zend Framework | http://framework.zend.com/

没有评论: