Codeigniter Fatal Error Call to a member function result() on boolean
I ran the query without putting return and got a syntax error. The problem was anything regarding USER
had to become [USER]
How to fix this 'Call to a member function row() on boolean' error?
I think the problem is with the query:
SELECT * from sma_sales desc limit 1 where customer_id = '$id'
Try something like this:
SELECT * from sma_sales where customer_id = '$id' order by `sales_date` desc limit 1
You need to use the ORDER BY
clause to do the sorting.
Also, make sure you escape the $id
before including it inside the query. Have a look at this.
Another suggestion is that, you could check whether the $result
is set or not. Because in case of errors, it would return NULL. Read more about it here.
getting error Call to a member function result() on boolean when i try to use group_by function in codeigniter
My guess is the sales_id
column name on this line is ambiguous :
->group_by('sales_id');
So you could change it either using sales.sales_id
or invoice.sales_id
:
->group_by('s.sales_id');
Codeigniter - Call to a member function result_array() on boolean - Local setup Installation error
Try to replace:
return $result = $this->db->get()->result_array();
with
return $this->db->get() ? $this->db->get()->result_array() : [];
It names ternary operator, works similar to if statement
:
if ($this->db->get()) {} else {}
This error occurs cause of $this->db->get()
returns a boolean value (true/false)
Call to a member function result() on boolean error after switching to sqlsrv dbdriver
First things first, NEVER put variables directly into a query. Always use parameter binding like this:
function get_myeligible_info($id)
{
$sql = "SELECT * FROM emp_list_manila WHERE employee_empid = ?";
$query = $this->db->query($sql, [$id]);
return $query->result();
}
For stored procedures, you can't just call them by name, you have to use EXEC
:
function get_for_batch_insert2()
{
$query = $this->db->query("EXEC INSERT_TTUMBATCH");
return $query->result();
}
For both these calls, you should be checking for errors and dealing with them appropriately:
function get_for_batch_insert2()
{
$query = $this->db->query("EXEC INSERT_TTUMBATCH");
if ($query) {
return $query->result();
} else {
return false;
}
}
Related Topics
How to Get Next Id of Autogenerated Field in Laravel for Specific Table
Sql Get an Id from a Column Where Ids Separated by Commas
How to Submit Multiple PHP Forms While Each Form Has Its Own Submit Button
How to Prevent Mails Sent Through PHP Mail() from Going to Spam
Laravel Composer Sees Wrong PHP Version
Count Same Values in Array and Combine into Array
Laravel Convert Query MySQL to Model Query
Regex - Exclude "-" Between Numbers
How to Store Values from Foreach Loop into an Array
How to Throw an Error Message If Username Is Already Registered
Download a Facebook Video (.Mp4) Via PHP
Create Line Break in Whatsapp Message