I really NEED the mysql_num_rows() functionality in v.6.19 so I figured I could just add it back.

I edited includes/database.mysql.inc, and added:

function db_num_rows($result) {
 $array = mysql_num_rows($result);
 return $array[0];
}

However when I try to use db_num_rows($query) I get the error: "Call to undefined function db_num_rows()"

How can I re-instate mysql_num_rows() in my 6.x installation?

Thanks.

PS: The db_result() alternatives do not seem to work on complex queries, like this one ...

"SELECT DISTINCT(users.uid) AS uid_1,
users.uid AS uid,
users.name AS users_name,
users.mail AS users_mail,
users.picture AS users_picture,
profile_values_profile_name.value AS profile_values_profile_name_value,
profile_values_profile_name.uid AS profile_values_profile_name_uid,
profile_values_profile_address.value AS profile_values_profile_address_value,
profile_values_profile_city.value AS profile_values_profile_city_value,
profile_values_profile_state.value AS profile_values_profile_state_value,
profile_values_profile_zip.value AS profile_values_profile_zip_value,
profile_values_profile_description.value AS profile_values_profile_description_value,
userpoints.points AS userpoints_points,
comments.uid AS comments_uid,
comments.cid AS comments_cid,
comments.subject AS comments_subject,
comments.comment AS comments_comment
 FROM users users 
 LEFT JOIN profile_values profile_values_profile_name ON users.uid = profile_values_profile_name.uid AND profile_values_profile_name.fid = '12'
 LEFT JOIN profile_values profile_values_profile_address ON users.uid = profile_values_profile_address.uid AND profile_values_profile_address.fid = '14'
 LEFT JOIN profile_values profile_values_profile_city ON users.uid = profile_values_profile_city.uid AND profile_values_profile_city.fid = '15'
 LEFT JOIN profile_values profile_values_profile_state ON users.uid = profile_values_profile_state.uid AND profile_values_profile_state.fid = '16'
 LEFT JOIN profile_values profile_values_profile_zip ON users.uid = profile_values_profile_zip.uid AND profile_values_profile_zip.fid = '17'
 LEFT JOIN profile_values profile_values_profile_description ON users.uid = profile_values_profile_description.uid AND profile_values_profile_description.fid = '20'
 LEFT JOIN userpoints userpoints ON users.uid = userpoints.uid
 LEFT JOIN comments comments ON users.uid = comments.uid
 WHERE LENGTH((profile_values_profile_name.value)) > 0
 GROUP BY uid_1
  ORDER BY userpoints_points DESC
  LIMIT 5";

I unsuccessfully tried several arrangements, like:

"SELECT DISTINCT(users.uid) AS uid_1,
COUNT(DISTINCT(users.uid)) AS uid_count,
 ...

and then

$result = db_result(db_query($query));

and then

while($row = db_fetch_array($result)) {
$uid_count = $row['uid_count'] ...

or

while($row = db_fetch_object($result)) {
$uid_count = $row->uid_count ...

In this situation, $uid_count always ends up as '1'.

If I could just do "$uid_count = mysql_num_rows($query)" I would be happy.

Comments

nevets’s picture

Are you sure you are not using mysqli?

Stupidscript’s picture

I get the same error whether I put my db_num_rows() in

database.inc,
database.mysql.inc,
database.mysqli.inc, or
database.mysql-common.inc,

"Call to undefined function db_num_rows()"

nevets’s picture

That does not make sense since database.inc is always included. Silly test, what if you define the function in your module?

Stupidscript’s picture

Thanks for your continuing interest.

This is not a module ... it's a PHP "content" page that is being used *instead* of a Views or Panel construct to execute a query and display the results. I am using the "container code" generated by an aborted Views/Panels attempt with my custom PHP code within the "article.." section of that code.

Everything works great ... except for getting a count of all records returned by the query.

Perhaps a useful note: Earlier, I left the custom function exposed in database.mysqli.inc when I also added it to database.inc. When the page was reloaded, database.mysqli.inc threw the error: "Cannot redeclare db_num_rows() (previously declared in..database.inc" ... so clearly the system is aware of my addition, and is including both files.

Amusingly, when I commented it out of database.mysqli.inc, leaving it exposed in database.inc, I *still* get the "Call to undefined function db_num_rows()" error. So Drupal finds it when its a conflict with a previous declaration, but it can't find it when invoked by my PHP "content" page.

(Also note that I clear my Drupal cache with each test.)

I appreciate your continuing assistance.