num_rows() problem in the count_all_results - 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: num_rows() problem in the count_all_results (/showthread.php?tid=72747) |
num_rows() problem in the count_all_results - CodeArt - 02-06-2019 Hi guys, I use the count_all_result function, and if I set a non existent column name in WHERE clause, then throw an error. In the WHERE clause have dynamic column name, so incorrect column names may occur Code: $this->db->select('column_1'); Error: Call to a member function num_rows() on a non-object This is in the count_all_results function of DB_query_builder. Code: public function count_all_results($table = '', $reset = TRUE) Here is a possible solution, but I don't want to overwrite the CI code: Code: if(is_object($result)){ Is there any good solution for this? RE: num_rows() problem in the count_all_results - php_rocs - 02-06-2019 @CodeArt, Why would you want an dynamic variable to return an invalid column name? Why don't you validate that the dynamic variable is a column name then if it is, then run your query. RE: num_rows() problem in the count_all_results - CodeArt - 02-07-2019 (02-06-2019, 07:35 PM)php_rocs Wrote: @CodeArt, This table can be dynamically expanded with columns by user. I check the exists columns before query, but if something yet it goes wrong, I would like to check the error for own error handling, and I don't want default num_rows error message. RE: num_rows() problem in the count_all_results - php_rocs - 02-07-2019 @CodeArt, Try using this... https://www.codeigniter.com/user_guide/database/queries.html#handling-errors RE: num_rows() problem in the count_all_results - CodeArt - 02-07-2019 (02-07-2019, 08:22 AM)php_rocs Wrote: @CodeArt, Thanks, I using this, and works fine with simple get queries, but not work with count_all_result for the previously written reasons |