Incorrect use of db_affected_rows() in api_search_listing()
| Project: | API |
| Version: | HEAD |
| Component: | Search |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | duplicate |
Jump to:
In api_search_listing(), the drupal function db_affected_rows() is called twice, and both times the $result parameter is passed to the function.
However, according to http://api.drupal.org/api/function/db_affected_rows/6 this function doesn't actually take any parameters. So $result should probably be removed in the calls to db_affected_rows().
To be honest, I don't even understand how this code works, because according to http://us2.php.net/manual/en/function.mysql-affected-rows.php mysql_affected_rows() returns "the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier". Since in api_search_listing() the most recent calls to db_query() were both SELECT statements, I don't see what's going on.
For reference, here is the relevant portion of the function:
<?php
function api_search_listing($branch_name) {
$search_text = func_get_args();
array_shift($search_text);
$search_text = implode('/', $search_text);
drupal_set_title(t('Search for %search', array('%search' => $search_text)));
// Exact match.
$result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title = '%s'", $branch_name, $search_text);
$count = db_affected_rows($result);
if ($count != 1) {
// Wildcard search.
$result = db_query("SELECT * FROM {api_documentation} WHERE branch_name = '%s' AND title LIKE '%%%s%%'", $branch_name, $search_text);
$count = db_affected_rows($result);
[...]
}
?>
#1
I fixed #344489: db_affected_rows() after SELECT query