CodeIgniter Forums
$result->fetch_assoc() is failing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: $result->fetch_assoc() is failing (/thread-70689.html)



$result->fetch_assoc() is failing - richb201 - 05-15-2018

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



RE: $result->fetch_assoc() is failing - Paradinight - 05-15-2018

(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/database/results.html#result-arrays


RE: $result->fetch_assoc() is failing - richb201 - 05-15-2018

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?


RE: $result->fetch_assoc() is failing - ciadmin - 05-15-2018

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.


RE: $result->fetch_assoc() is failing - richb201 - 05-15-2018

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?


RE: $result->fetch_assoc() is failing - richb201 - 05-15-2018

Well, this line seems to work

$data=$result->row_array();

so I am ok for the moment!


RE: $result->fetch_assoc() is failing - peter2015 - 05-15-2018

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

https://forum.codeigniter.com/thread-70678.html


RE: $result->fetch_assoc() is failing - InsiteFX - 05-16-2018

That's pure MySQLi code which means that he never made a MySQLi connection.