Anthony
Anthony

Reputation: 4050

Count Records Returned MySQL Doctrine

How do I check the number of records returned from a search of my MySQL database with a statement like this:

$searchKey = 'Something to search for'; 
$searchResults = Doctrine::getTable('TableName')->createQuery('t')- 
    >where('columnName LIKE ?','%'.$searchKey.'%')->execute(); 

Upvotes: 4

Views: 12060

Answers (2)

Rahul
Rahul

Reputation: 1876

Wouldn't

Doctrine::getTable('TableName')->createQuery('t')
->where('columnName LIKE ?','%'.$searchKey.'%') ->execute() ->rowCount();

fetch the results from the database?

In that case,

Doctrine::getTable('TableName')->createQuery('t')
->where('columnName LIKE ?','%'.$searchKey.'%') ->count()

be a better solution?

Upvotes: 6

Galen
Galen

Reputation: 30170

maybe

$searchResults->rowCount();

from here

Upvotes: 7

Related Questions