Zend DB query() - 如何执行数据库更新?

时间:2011-12-19 15:40:26

标签: zend-framework

此代码的最后一行似乎返回一个对象但不执行数据库查询。如何更改以实际执行数据库更新?

$sql = "UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'";
$bind = array($addresses,$status,$id);
$res = $this->getAdapter()->query($sql,$bind);

这是$ res中对象的var转储:

object(Zend_Db_Statement_Pdo)[102]
  protected '_fetchMode' => int 2
  protected '_stmt' => 
    object(PDOStatement)[100]
      public 'queryString' => string 'UPDATE vi_admin_email SET processed_send_list = '?', status = '?' WHERE id = '?'' (length=80)
  protected '_adapter' => 
    object(Zend_Db_Adapter_Pdo_Mysql)[43]
      protected '_pdoType' => string 'mysql' (length=5)
      protected '_numericDataTypes' => 
        array
          0 => int 0
          1 => int 1
          2 => int 2
          'INT' => int 0
          'INTEGER' => int 0
          'MEDIUMINT' => int 0
          'SMALLINT' => int 0
          'TINYINT' => int 0
          'BIGINT' => int 1
          'SERIAL' => int 1
          'DEC' => int 2
          'DECIMAL' => int 2
          'DOUBLE' => int 2
          'DOUBLE PRECISION' => int 2
          'FIXED' => int 2
          'FLOAT' => int 2
      protected '_defaultStmtClass' => string 'Zend_Db_Statement_Pdo' (length=21)
      protected '_config' => 
        array
          'host' => string 'localhost' (length=9)
          'username' => string 'root' (length=4)
          'password' => string '' (length=0)
          'dbname' => string 'vi' (length=2)
          'charset' => null
          'persistent' => boolean false
          'options' => 
            array
              ...
          'driver_options' => 
            array
              ...
      protected '_fetchMode' => int 2
      protected '_profiler' => 
        object(Zend_Db_Profiler)[44]
          protected '_queryProfiles' => 
            array
              ...
          protected '_enabled' => boolean false
          protected '_filterElapsedSecs' => null
          protected '_filterTypes' => null
      protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
      protected '_connection' => 
        object(PDO)[85]
      protected '_caseFolding' => int 0
      protected '_autoQuoteIdentifiers' => boolean true
      protected '_allowSerialization' => boolean true
      protected '_autoReconnectOnUnserialize' => boolean false
  protected '_attribute' => 
    array
      empty
  protected '_bindColumn' => 
    array
      empty
  protected '_bindParam' => 
    array
      empty
  protected '_sqlSplit' => 
    array
      0 => string 'UPDATE vi_admin_email SET processed_send_list = , status =  WHERE id = ' (length=71)
  protected '_sqlParam' => 
array
  0 => string 'UPDATE vi_admin_email SET processed_send_list = , status =  WHERE id = ' (length=71)

protected'_queryId'=>空

3 个答案:

答案 0 :(得分:2)

要更新Zend Framework中的条目,请执行以下操作:

$data = array(
    'processed_send_list' => $addresses,
    'status' => $status
);

$dbAdapter = $this->getAdapter();

$where = $dbApdapter->quoteInto('id = ?', $id);

$this->update($data, $where);

使用Zend_Db_Table,要更新的数据在associative array中指定为第一个参数。执行查询时,将提供所提供的数据。您还必须将where语句作为字符串包括在内,例如id = 1作为第二个参数。在上面的示例中,quoteInto是可选的,因为您可以手动编写where,但如果您手动执行此操作,则不会转义该值。

答案 1 :(得分:0)

我以为我读了“查询”,但你问的是“更新”。

所以声明如下:

$水库>执行()

忘记我之前写的内容。

答案 2 :(得分:0)

试试这一行代码,

$res = $this->getAdapter()->query("UPDATE vi_admin_email SET processed_send_list = '$addresses', status = '$status' WHERE id = '$id'");