CodeIgniter Forums
codeigniter 3.1.7 result query array has an issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: codeigniter 3.1.7 result query array has an issue (/showthread.php?tid=70135)



codeigniter 3.1.7 result query array has an issue - 55953.kt - 02-25-2018

Hello every one

i have been having an issue with the database query returning a boolean instead of result_array() or result_object! it is very frustrating to have to go twist code around at each stap, can anyone give a good suggestion to solving this problem?

below is the normal query that was supposed to return a result.

$query = $this->db->query('MY_QUERY');

return $query->result_array();


To be more precise the core code is generating a fatal_error : this is the error i am getting using form validation core library to validate the in put!

Fatal error: Call to a member function num_rows() on boolean in C:\xampp\htdocs\MY_PROJECT\system\libraries\Form_validation.php on line 1122


RE: codeigniter 3.1.7 result query array has an issue - skunkbad - 02-25-2018

Show more code.


RE: codeigniter 3.1.7 result query array has an issue - falcon812311 - 02-25-2018

Declare form_validation library.
exp:
Put in your controller.
$this->load->library('form_validation');

ref: https://www.codeigniter.com/userguide3/libraries/form_validation.html


RE: codeigniter 3.1.7 result query array has an issue - Wouter60 - 02-26-2018

Did the same code work in 3.1.6 and below?

If $query->result_array() returns a boolean (FALSE, that is), there's a syntax error in your query. So, please, check that first.
A message error from the form validation library, as a result of the code you shared, is very unlikely. Show some more code.


RE: codeigniter 3.1.7 result query array has an issue - santanu - 02-26-2018

(02-26-2018, 12:03 AM)Wouter60 Wrote: Did the same code work in 3.1.6 and below?

If $query->result_array() returns a boolean (FALSE, that is), there's a syntax error in your query. So, please, check that first.
A message error from the form validation library, as a result of the code you shared, is very unlikely. Show some more code.

hi num_rows() will not work on $query->result_array() , it will throw error. you can use $query-num_rows()  or count($query->result_array())


RE: codeigniter 3.1.7 result query array has an issue - InsiteFX - 02-26-2018

If num_rows() returns an error it means the query did not get ant results back.

Use this to check your query:

PHP Code:
$this->db->last_query() 

Check num_rows:

PHP Code:
if ($query->num_rows() > 0)
{
 
   // Success

}
else
{
 
   // Error



Sounds like you have an error in your query...


RE: codeigniter 3.1.7 result query array has an issue - dave friend - 02-26-2018

PHP Code:
$query  $this->db->query('MY_QUERY'); 

In the code above $query can end up being set to TRUE, FALSE, or a CI_DB_result object.

Read the Docs

There can be several reasons for a FALSE return, but it is usually because 'MY_QUERY' is invalid. That's what I usually do wrong anyway. Dodgy

Best practice would undoubtedly recommend checking the return of query() before attempting to use it. To be perfectly clear, you want to make sure it is a CI_DB_result object (or not a bool) before using it on a method like num_rows() and any of the result*() methods. For instance

PHP Code:
$query  $this->db->query('MY_QUERY');
if(
is_bool($query)
{
    
// respond to the problem
}
else
{
    return 
$query->result_array();