首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ZendFramework2通过TableGateway对象更新查询

ZendFramework2通过TableGateway对象更新查询
EN

Stack Overflow用户
提问于 2017-07-10 11:33:27
回答 2查看 1.7K关注 0票数 1
代码语言:javascript
复制
public function update($table, $where = array(), $data_arr = array()){

    print_r($data_arr);

    $adapter = $this->tableGateway->getAdapter();

    $projectTable;

    if($table != null){
        $projectTable = new TableGateway($table, $adapter);
    }else{
        $projectTable = new TableGateway('account_master', $adapter);
    }
    echo "158";

    try {
        echo "123";
        $rowset = $projectTable->update(function(Update $update) use ($where, $data_arr) {

                $update->set(array('statement_no' => '01010'));

                $update->where($where);

            echo $update->getSqlString();
        });
    } catch (\Exception $e) {
            print_r($e);
    }

    print_r($rowset);
    die();
}

输出输出: 158123 --它给我传递作为参数传递的set()函数中的pass数组。此外,我还尝试将对象转换为数组((arrya)$objetc),但它对我来说并不适用。

代码语言:javascript
复制
[10-Jul-2017 05:11:34 America/Denver] PHP Catchable fatal error:  Argument 1 passed to Zend\Db\Sql\Update::set() must be of the type array, object given, called in /home2/flywing1/vendor/zendframework/zend-db/src/TableGateway/AbstractTableGateway.php on line 336 and defined in /home2/flywing1/vendor/zendframework/zend-db/src/Sql/Update.php on line 93
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-10 16:17:12

您可以通过实现Zend\Db\Sql\Update对象来做到这一点。您可以使用TableGateway创建该对象。您应该能够在您的模型中执行以下操作

代码语言:javascript
复制
public function update($set, $where)
{
    // Here is the catch  
    $update = $this->tableGateway->getSql()->update();
    $update->set($set);
    $update->where($where);

    // Execute the query
    return $this->tableGateway->updateWith($update);
}
票数 2
EN

Stack Overflow用户

发布于 2017-07-10 11:45:00

试试看,我有同样的问题,我试过这个,而且成功了。

代码语言:javascript
复制
$rowset = $projectTable->update(array('statement_no' => '01010'), $where);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45010951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档