PHP Classes

Problem with mysql_num_fields()

Recommend this page to a friend!

      PHP MySQL to MySQLi  >  All threads  >  Problem with mysql_num_fields()  >  (Un) Subscribe thread alerts  
Subject:Problem with mysql_num_fields()
Summary:mysql_num_fields() returns the wrong number of fields
Messages:1
Author:Mike Smith
Date:2023-10-02 19:31:46
 

  1. Problem with mysql_num_fields()   Reply   Report abuse  
Picture of Mike Smith Mike Smith - 2023-10-02 19:31:46
I have found this class to be very useful getting an old application running on AWS.

But I did get a problem with mysql_num_fields(). I have pasted below my version which seems to work now:-

public static function mysql_num_fields($result){

// -- This doesn't work like in mysql. It returns the number
// -- of fields in the last query, not the number of fields
// -- in $result!
//$link = self::$currObj;
//return mysqli_field_count($link);

// -- This seems to work!
// return $result->field_count;

// -- Surely it should always been this?
return mysqli_num_fields($result);
}

I found it when the code I was getting to work was doing something like:-

$result1 = mysql_query(..,);
$result2 = mysql_query(...);
$fields = mysql_num_fields($result1);

In this case $fields contained the number of fields in $result2 not in $result1.