zf2 附加到现有列内容

zf2 append to existing column content

我正在尝试使用 mysql 的 CONCAT 功能,使用 zf2(Zend Framework)。

如何附加到现有文本列值?

例子

旧值:image1Path
新值:image1Path**image2path.

我在模型 table 文件中的函数。

public function updatePresImages($orderId,$newImageName)
{   
    $data = array(
        'prescription_upload_path'      => ??, 
        'date_updated'  => date('Y-m-d H:i:s'),
    );
    $updateStatus=$this->tableGateway->update($data, array('user_medicine_order_id' => $orderId));
    return  $updateStatus;          
}

从你的代码中我可以看出你在使用 TableGatway。也许你可以试试这个:

public function updatePresImages($orderId,$newImageName)
{   
    $sql = "UPDATE yourTable SET prescription_upload_path= CONCAT(prescription_upload_path, '##', '$newImageName'), date_updated=now() WHERE user_medicine_order_id= '$orderId'"
    $updateStatus=$this->tableGateway->getAdapter()->driver->getConnection()->execute($sql);

    return  $updateStatus;          
 }

Table 实现要求更新的网关方式是使用 Zend Expression。

在模型顶部包含以下 use 语句 class

use Zend\Db\Sql\Expression;

然后

$this->tableGateway->update(array(
        'prescription_upload_path' => new Expression('CONCAT(prescription_upload_path, "##", "'.$newImageName.'")'),
        'date_updated' => new Expression('now()')
    ),
    array(
        'user_medicine_order_id' => $orderId,

    )
);