Count Records Returned MySQL Doctrine

2019-06-26 07:36发布

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(); 

2条回答
做自己的国王
2楼-- · 2019-06-26 08:13

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?

查看更多
三岁会撩人
3楼-- · 2019-06-26 08:14

maybe

$searchResults->rowCount();

from here

查看更多
登录 后发表回答