插入..使用zend db从...中选择

sro*_*oes 4 php zend-db

我有以下原始查询将项目从购物车移动到订单表:

insert into webshop_order_item (
    order_id,
    product_id,
    count
)
select
    1,
    product_id,
    count
from 
    webshop_cart
Run Code Online (Sandbox Code Playgroud)

我正在使用Zend DB进行所有建模.我想知道是否有一种方法可以实现上述查询的目标而无需使用原始查询?

alt*_*ern 6

尚无法从zend db中的select中插入.但是,如果您只需要一个适配器的此功能,那么您可以使用类似于下面给出的方法:

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);
} 
Run Code Online (Sandbox Code Playgroud)