By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,452 Members | 974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,452 IT Pros & Developers. It's quick & easy.

What does PDO (MYSQL) return when there is an empty result set?

guillermobytes
P: 77
Hi,

I was wondering what does PDO return when there are no records matching the query? i.e. i query for a column.name = 'John' and there is no 'John' in the table.


thanks for your answer.

guillermobytes
Mar 15 '10 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hey.

It returns an "empty" PDOStatement object, in much the same way the classic mysql_query function returns an "empty" resource.
Mar 15 '10 #2

guillermobytes
P: 77
thnaks Atli,

so how should i test that it is an emptyPDO statement?
Expand|Select|Wrap|Line Numbers
  1. $dbh = new PDO('connection info',...);
  2. $sql = 'SELECT something FROM somewhere WHERE id = inexistent';
  3. $ps = $dbh->query($sql);
  4. if ($ps->rowCount() > 0) {
  5.     $resultSet = $ps->fetchAll();
  6.     print_r($resultSet);
  7. } else {
  8.     echo 'Empty result set';
  9. }
Mar 16 '10 #3

Markus
Expert 5K+
P: 6,050
PDOStatement::rowCount() does that for you.
Mar 16 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.