I have a variable called $result which should store all the results from my database query however when I run print ($result) it gives an error message:
A PHP Error was encountered
Severity: 4096
Message: Object of class CI_DB_mysql_result could not be converted to
stringFilename: models/control_panel_model.php
Line Number: 72
Here is my model code:
public function view_record($record_id)
{
$criteria = array
(
'procedure_id' => $record_id
);
echo $this->db->count_all('procedure');
return;
$this->db->select('procedure.procedure_id, procedure.patient_id, procedure.department_id, procedure.name_id , procedure.dosage_id');
$this->db->from ('procedure');
$this->db->join('patient', 'patient.patient_id = procedure.patient_id', 'inner');
$this->db->join('department', 'department.department_id = procedure.department_id', 'inner');
$this->db->join('procedure_name', 'procedure_name.procedure_name_id = procedure.name_id', 'inner');
$this->db->join('dosage', 'dosage.dosage_id = procedure.dosage_id', 'inner');
$this->db->where('procedure_id', $record_id);
$result = $this->db->get();
print($result);
return ;
}
The reason I am using a print function is just to test if my query is working and it has values. How do I achieve this.
Thanks
EDIT!!!
Here is what I get in var_dump();
object(CI_DB_mysql_result)#22 (8) {
["conn_id"]=> resource(30) of type (mysql link persistent)
["result_id"]=> resource(40) of type (mysql result)
["result_array"]=> array(0) { }
["result_object"]=> array(0) { }
["custom_result_object"]=> array(0) { }
["current_row"]=> int(0)
["num_rows"]=> int(0)
["row_data"]=> NULL
}
I HAVE ADDED THE FOLLOWING CODE:
if ($result->num_rows >0) {
echo “Data”;
}
else {
echo “No Data”;
}
IT IS SAYING THERE IS “NO DATA” so my query must be crap and wrong , so I need to redesign query. THERE IS DATA IN MY DATABASE SO must be query
===========================================
Here is my schema
https://i.stack.imgur.com/zSHSQ.png

The object in question (
CI_DB_mysql_result) is missing the__toStringimplementation that’s why you get the error.However, this can mean that the object can not be usefully converted to string.
Instead you should convert the objects data to string first on your own for the purpose of your
printoperation. I can not say from the code you’ve posted which use you’re looking for specifically, so there is not more I can add to this.Please see Generating Query Results and Active Record Class.
Edit: For a quick and dirty string-printing, you can use
print_r, however I do not know if this is actually helpful for your case:That’s comparable to the suggestion given to use
var_dump. You should say which kind of information you would like to print actually and for this you should know the type of data the database returns. See the documentation ofget()Active Record Class for some examples how to work with the return values.