0

我将 Zend_Db 与 Oracle 适配器一起使用,并且尝试使用子句IN()中的语句执行查询WHERE

该语句不会产生任何错误,也不会执行更新。我尝试了以下形式:

$arrLinesCanceled = array('0000000001', '0000000002');

// attempt 1
$db->query(
    "UPDATE my_table SET STATUS = :status WHERE id IN(:lineIds)",
    array(
        'lineIds' => $arrLinesCanceled,
        'status' => 'C',
))->execute();

// attempt 2 (this actually errors out with 'not all parameters are bound')
$db->query(
    "UPDATE my_table SET STATUS = :status WHERE id IN(:lineIds)"
)->execute(array(
    'lineIds' => $arrLinesCanceled,
    'status' => 'C',
));

// attempt 3
$stmtUpdateDetailStatus = $db->prepare(
    "UPDATE my_table SET STATUS = :status WHERE id IN(:lineIds)");

$stmtUpdateDetailStatus->execute(array(
    'lineIds' => $arrLinesCanceled,
    'status' => 'C',
));

// last, very desperate attempt
$db->query("UPDATE my_table SET STATUS = :status WHERE id IN(:lineIds)", array(
    ':lineIds' => $arrLinesCanceled,
    ':status' => 'C',
))->execute(array(
    ':lineIds' => $arrLinesCanceled,
    ':status' => 'C',
));

为了确保输入正确,这里是实际print_r$arrLinesCanceled

Array( [0] => 6617 [1] => 6618)

Oracle 11 或 Zend_Db 适配器不支持吗?我看不出有什么问题...

4

1 回答 1

0

关于文档,当在 SQL 语法中使用命名占位符(那些:placeholder)时,您还需要在参数数组中使用确切的占位符名称 - 这意味着也使用冒号:

$db->query(
    "UPDATE MOVE_LIST_EMPLOYEE_DETAILS SET STATUS = :status 
     WHERE MOVE_LIST_DETAIL_ID IN(:lineIds)"
)->execute(array(
    ':lineIds' => $arrLinesCanceled,
    ':status' => 'C',
));
于 2013-10-23T15:02:40.853 回答