How to use bind variables with Zend_Db_Table->update() in the where clause

前端 未结 1 382
囚心锁ツ
囚心锁ツ 2021-02-11 06:01

If I want to use the Zend_Db_Table->update() method to update my table with data, I cannot find anyway to use bind variables in the \"where\" clause.

The

相关标签:
1条回答
  • 2021-02-11 06:41

    You are only updating data, RDBMS (I assume MySQL) doesn't cache UPDATE queries. If you still want to use bind variables (security? performance?), you will have to use prepared statements:

    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
    $stmt = $db->prepare("UPDATE table SET key = :key, value = :value");
    
    foreach ($data as $key=>$value) {
        $stmt->bindParam('key', $key);
        $stmt->bindParam('value', $value);
        $stmt->execute();
    }
    

    But unless you are having millions of UPDATE queries in a batch I don't think you should bother with this. Just use the $table->update($data, $where);

    0 讨论(0)
提交回复
热议问题