codeigniter 3.1.7 result query array has an issue |
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
Declare form_validation library.
exp: Put in your controller. $this->load->library('form_validation'); ref: https://www.codeigniter.com/userguide3/l...ation.html
This is me. JK not me.
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. (02-26-2018, 12:03 AM)Wouter60 Wrote: Did the same code work in 3.1.6 and below? 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())
Santanu Kumar Pati
Software Engineer MTech. In Computer Science & Engeering Biju Pattnaik University Of Technology, Odisha, India
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) Sounds like you have an error in your query... What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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. ![]() 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'); |
Welcome Guest, Not a member yet? Register Sign In |