2011-12-19 39 views
0

此代码的最后一行似乎返回一个对象,但不执行数据库查询。我为了实际执行数据库更新而进行了哪些更改?Zend DB query() - 如何执行数据库更新?

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

这里是对象在$ RES一个变种转储:

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) 

保护 '_queryId'=>空

+0

$这是指? – emaillenin 2011-12-19 17:20:56

回答

2

要更新Zend框架的项目你做如下:

$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是specfied数据作为第一个参数。查询执行时提供的数据将被转义。您还必须包含where语句作为字符串,如id = 1作为第二个参数。在上面的示例中,quoteInto是可选的,因为您可以手动编写该位置,但如果手动执行该值,则该值不会被转义。

0

我想我读 “查询”,但你问“更新”。

所以语句应该是:

$水库>的execute()。

忘记我之前写的。

+0

嗯..不起作用。当我检查SQL时,它没有绑定参数,即有三个?占位符,而不是实际的参数。 – Owen 2011-12-20 15:58:15

0

尝试的这一行代码,

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

是的,我已经试过,它的工作原理...但我想绑定参数的SQL语句。 – Owen 2011-12-20 15:58:27