Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If i use fetchCol(), I get results, but rowCount() returns 0.
$count = db_query("SELECT nid from {node} where title = :orgname and type = :type;", array (
':orgname' => $org_name,
':type' => $type,
))->rowCount();
dpm ($count);
Is this a bug? or am I missing something?
Thanks!!!
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedAre you sure your values for the title and type should actually return anything? I copy and pasted this and added variables above for $org_name and $type, and it worked for me.
Comment #2
phen CreditAttribution: phen commentedYes, it definitely returns results if I use the fetchCol() method.
In this case worked around it, not using rowCount(), but i continue to get this behavior with other completely different queries. It's not critical, so far I can work around it, but it's strange.
Any other ideas?
Comment #3
phen CreditAttribution: phen commentedUpdate:
RowCount() works on my production site but not on my local machine sandbox. So there must be some settings somewhere that disable it. Specs:
Production site:
MySQL 5.1.36
PHP 5.2.10
localhost:
MySQL 5.0.37
PHP 5.2.13
I wonder if upgrading MySQL on localhost would make a difference. It shouldn't, since it meets the minimum system requirements for D7. I don't think I have time to upgrade now, but I'll try it soon and report back.
Thanks for any input!
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedPDOStatement::rowCount() is only guaranteed to return something for DELETE, INSERT, or UPDATE statements.
If you want to count a number of something, build a
COUNT(*)
query using SelectQuery::countQuery().Comment #5
phen CreditAttribution: phen commentedThanks for the help!
Comment #6
phen CreditAttribution: phen commentedThe documentation at http://drupal.org/node/1251174 implies that result->rowCount() will work on a select query.
Can I suggest that the documentation be updated? I'd draft an edit myself but I'm not sure I understand the correct usage well enough yet...
More details:
The first line of the document is
Then later, without indicating that a different type of query is required:
Thanks!
Comment #7
jhodgdonThat page is incorrect. The documentation of the rowCount() method (and the comment above) are correct:
http://api.drupal.org/api/drupal/includes--database--database.inc/functi...
So the page should be corrected. Moving to correct issue queue.
If you would like to help, just click "Edit" at the top of that page and fix it. Thanks!
Comment #8
kristiaanvandeneyndeDone: http://drupal.org/node/1251174
Please review.
Comment #9
snufkin CreditAttribution: snufkin commentedI think its clear now.