2.3.2. Reading From The Table

2.3.2.1. Fetching A Single Row

Use the fetchRow() method to retrieve a single Row. It can be called either by primary key, or with a select() query.

// fetch by primary key thread_id = 1

$threadRow = $threadTable->fetchRow('1');

$threadRow = $threadTable
    ->select()
    ->where('thread_id = ', '1')
    ->fetchRow();

Note:

If fetchRow() does not find a match, it will return null.

2.3.2.2. Fetching An Array Of Rows

The fetchRows() method works the same as fetchRow(), but returns an array of Rows. It can be called either with primary keys, or with a select() query.

// fetch thread_id 1, 2, and 3
$threadRows = $threadTable->fetchRows([1, 2, 3]);

// This is identical to the example above, but uses the `select()` variation.
$threadRows = $threadTable
    ->select()
    ->where('thread_id IN ', [1, 2, 3])
    ->fetchRows();

Note:

If fetchRows() does not find a match, it will return an empty array.

2.3.2.3. Query Construction

The Table::select() method returns a query object that you access to all the underlying SQL query methods. See the query system documentation for more information.

2.3.2.4. Identifier Quoting

The select() method will automatically quote the table name in the FROM clause.

In addition, the fetchRow() and fetchRows() methods will automatically quote the primary key column names in the WHERE clause.

You can manually quote any other identifiers using the Select object's quoteIdentifier() method.