官方手册中介绍说:

 

根据主键查找数据

通过调用find()方法,可以使用主键值轻松地在表中检索数据.假如你只想要查询某 一条数据,该方法将回返回一个zend_db_table_row对象,而当你想要查询多条记录时 ,将会返回一个zend_db_table_rowset对象.

<?php
class RoundTable extends Zend_Db_Table {}

$table = new RoundTable();

// SELECT * FROM round_table WHERE id = "1"
$row = $table->find(1);

// SELECT * FROM round_table WHERE id IN("1", "2", 3")
$rowset = $table->find(array(1, 2, 3));
?>
 其实       

" 假如你只想要查询某 一条数据,该方法将回返回一个zend_db_table_row对象"错误的,经测试返回的也是一个"zend_db_table_rowset对象":

代码:

<?php

require_once 'Zend/Db.php';

$params = array(

    'host' => '127.0.0.1',

    'username' => 'root',

    'password' => '',

    'dbname' => 'guestbook'

);

$db = Zend_Db::factory('PDO_MYSQL', $params);

// 为所有的Zend_Db_Table对象设定默认的adapter

require_once 'Zend/Db/Table.php';

Zend_Db_Table::setDefaultAdapter($db);

class Guestbook extends Zend_Db_Table {    

}

$table = new Guestbook();

// SELECT * FROM round_table WHERE id = "1"

$row = $table->find(1);

var_dump($row);

// SELECT * FROM round_table WHERE id IN("1", "2", 3")

$rowset = $table->find(array(1, 2, 3));

var_dump($rowset);

?>

结果:

object(Zend_Db_Table_Rowset)[6]
  protected '_data' => 
    array
      0 => 
        array
          'id' => string '1' (length=1)
          'email' => string 'ralph.schindler@zend.com' (length=24)
          'comment' => string 'Hello! Hope you enjoy this sample zf application!' (length=49)
          'created' => string '2011-10-14 09:09:56' (length=19)
  protected '_table' => 
    object(Guestbook)[3]
      protected '_definition' => null
      protected '_definitionConfigName' => null
      protected '_db' => 
        object(Zend_Db_Adapter_Pdo_Mysql)[1]
          protected '_pdoType' => string 'mysql' (length=5)
          protected '_numericDataTypes' => 
            array
              ...
          protected '_defaultStmtClass' => string 'Zend_Db_Statement_Pdo' (length=21)
          protected '_config' => 
            array
              ...
          protected '_fetchMode' => int 2
          protected '_profiler' => 
            object(Zend_Db_Profiler)[2]
              ...
          protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
          protected '_connection' => 
            object(PDO)[4]
              ...
          protected '_caseFolding' => int 0
          protected '_autoQuoteIdentifiers' => boolean true
          protected '_allowSerialization' => boolean true
          protected '_autoReconnectOnUnserialize' => boolean false
      protected '_schema' => null
      protected '_name' => string 'Guestbook' (length=9)
      protected '_cols' => 
        array
          0 => string 'id' (length=2)
          1 => string 'email' (length=5)
          2 => string 'comment' (length=7)
          3 => string 'created' (length=7)
      protected '_primary' => 
        array
          1 => string 'id' (length=2)
      protected '_identity' => int 1
      protected '_sequence' => boolean true
      protected '_metadata' => 
        array
          'id' => 
            array
              ...
          'email' => 
            array
              ...
          'comment' => 
            array
              ...
          'created' => 
            array
              ...
      protected '_metadataCache' => null
      protected '_metadataCacheInClass' => boolean true
      protected '_rowClass' => string 'Zend_Db_Table_Row' (length=17)
      protected '_rowsetClass' => string 'Zend_Db_Table_Rowset' (length=20)
      protected '_referenceMap' => 
        array
          empty
      protected '_dependentTables' => 
        array
          empty
      protected '_defaultSource' => string 'defaultNone' (length=11)
      protected '_defaultValues' => 
        array
          empty
  protected '_connected' => boolean true
  protected '_tableClass' => string 'Guestbook' (length=9)
  protected '_rowClass' => string 'Zend_Db_Table_Row' (length=17)
  protected '_pointer' => int 0
  protected '_count' => int 1
  protected '_rows' => 
    array
      empty
  protected '_stored' => boolean true
  protected '_readOnly' => boolean false
object(Zend_Db_Table_Rowset)[7]
  protected '_data' => 
    array
      0 => 
        array
          'id' => string '1' (length=1)
          'email' => string 'ralph.schindler@zend.com' (length=24)
          'comment' => string 'Hello! Hope you enjoy this sample zf application!' (length=49)
          'created' => string '2011-10-14 09:09:56' (length=19)
      1 => 
        array
          'id' => string '2' (length=1)
          'email' => string 'foo@bar.com' (length=11)
          'comment' => string 'Baz baz baz, baz baz Baz baz baz - baz baz baz.' (length=47)
          'created' => string '2011-10-14 09:09:56' (length=19)
  protected '_table' => 
    object(Guestbook)[3]
      protected '_definition' => null
      protected '_definitionConfigName' => null
      protected '_db' => 
        object(Zend_Db_Adapter_Pdo_Mysql)[1]
          protected '_pdoType' => string 'mysql' (length=5)
          protected '_numericDataTypes' => 
            array
              ...
          protected '_defaultStmtClass' => string 'Zend_Db_Statement_Pdo' (length=21)
          protected '_config' => 
            array
              ...
          protected '_fetchMode' => int 2
          protected '_profiler' => 
            object(Zend_Db_Profiler)[2]
              ...
          protected '_defaultProfilerClass' => string 'Zend_Db_Profiler' (length=16)
          protected '_connection' => 
            object(PDO)[4]
              ...
          protected '_caseFolding' => int 0
          protected '_autoQuoteIdentifiers' => boolean true
          protected '_allowSerialization' => boolean true
          protected '_autoReconnectOnUnserialize' => boolean false
      protected '_schema' => null
      protected '_name' => string 'Guestbook' (length=9)
      protected '_cols' => 
        array
          0 => string 'id' (length=2)
          1 => string 'email' (length=5)
          2 => string 'comment' (length=7)
          3 => string 'created' (length=7)
      protected '_primary' => 
        array
          1 => string 'id' (length=2)
      protected '_identity' => int 1
      protected '_sequence' => boolean true
      protected '_metadata' => 
        array
          'id' => 
            array
              ...
          'email' => 
            array
              ...
          'comment' => 
            array
              ...
          'created' => 
            array
              ...
      protected '_metadataCache' => null
      protected '_metadataCacheInClass' => boolean true
      protected '_rowClass' => string 'Zend_Db_Table_Row' (length=17)
      protected '_rowsetClass' => string 'Zend_Db_Table_Rowset' (length=20)
      protected '_referenceMap' => 
        array
          empty
      protected '_dependentTables' => 
        array
          empty
      protected '_defaultSource' => string 'defaultNone' (length=11)
      protected '_defaultValues' => 
        array
          empty
  protected '_connected' => boolean true
  protected '_tableClass' => string 'Guestbook' (length=9)
  protected '_rowClass' => string 'Zend_Db_Table_Row' (length=17)
  protected '_pointer' => int 0
  protected '_count' => int 2
  protected '_rows' => 
    array
      empty
  protected '_stored' => boolean true
  protected '_readOnly' => boolean false