Welcome Guest, Not a member yet? Register   Sign In
$result->fetch_assoc() is failing
#1

I am trying to modify my password code with some code I got from from Codex. The Codex code has this:

PHP Code:
       if(array_key_exists("returnType",$conditions) && $conditions['returnType'] != 'all'){
 
           switch($conditions['returnType']){
 
               case 'count':
 
                   $data $result->num_rows;
 
                   break;
 
               case 'single':
 
                   $data $result->fetch_assoc();   <<<<this line
                    break
;
 
               default:
 
                   $data '';
 
           }
 
       }else{
 
           if($result->num_rows 0){
 
               while($row $result->fetch_assoc()){
 
                   $data[] = $row;
 
               }
 
           }
 
       }

But the fetch_assoc line is failing with this errorCall to undefined method CI_DB_mysqli_result::fetch_assoc()

Anyone know why
proof that an old dog can learn new tricks
Reply
#2

(05-15-2018, 01:03 PM)richb201 Wrote: I am trying to modify my password code with some code I got from from Codex. The Codex code has this:

PHP Code:
       if(array_key_exists("returnType",$conditions) && $conditions['returnType'] != 'all'){
 
           switch($conditions['returnType']){
 
               case 'count':
 
                   $data $result->num_rows;
 
                   break;
 
               case 'single':
 
                   $data $result->fetch_assoc();   <<<<this line
                    break
;
 
               default:
 
                   $data '';
 
           }
 
       }else{
 
           if($result->num_rows 0){
 
               while($row $result->fetch_assoc()){
 
                   $data[] = $row;
 
               }
 
           }
 
       }

But the fetch_assoc line is failing with this errorCall to undefined method CI_DB_mysqli_result::fetch_assoc()

Anyone know why

Read the doc. https://www.codeigniter.com/user_guide/d...ult-arrays
Reply
#3

I see it that part of the manual. My result is this:

mysqli_result Object
(
[current_field] => 0
[field_count] => 10
[lengths] =>
[num_rows] => 6
[type] => 0
)

But the $result_array is [0]. The question is why would fetch_assoc() error out rather than return some type of return code?
proof that an old dog can learn new tricks
Reply
#4

A careful reading of the error message shows me **Call to undefined method CI_DB_mysqli_result::fetch_assoc()**

There is no fetch_assoc method in a result object.
Searching the CI3 user guide for "fetch_assoc" doesn't show any results.

My guess is that the code you found is inappropriate!

Passwords would normally be saved as the result of "password_hash", if that is what you are trying to do.
Reply
#5

(This post was last modified: 05-15-2018, 04:06 PM by richb201.)

aha, but there is a mysqli_fetch_assoc in php. Could the answer be to append the mysqli_ onto it? I tried that but it didn't work. Because that would presume that I used
 
mysqli_query instead of the actual line below.

       $result = $this->db->query($sql);


Here is the def of what mysqi_fetch_assoc does:

(PHP 5, PHP 7)

mysqli_result::fetch_assoc -- mysqli_fetch_assoc — Fetch a result row as an associative array

perhaps I can build a command that does the same thing as thing as this non-existing function call?
proof that an old dog can learn new tricks
Reply
#6

Well, this line seems to work

$data=$result->row_array();

so I am ok for the moment!
proof that an old dog can learn new tricks
Reply
#7

Guys .. I know its out of subject but can someone help me here please:

https://forum.codeigniter.com/thread-70678.html
Reply
#8

That's pure MySQLi code which means that he never made a MySQLi connection.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB