Home > Mobile >  codeigniter 4 mysqli_sql_exception #1064 in view
codeigniter 4 mysqli_sql_exception #1064 in view

Time:12-28

It's very strange for me. Because in codeigniter 4 one of my function is working in controller but not working in view. I am getting my data's from database in controller, but when I am trying to get same data from view it showing mysqli_sql_exception #1064.

Example codes:

In Controller (MyData.php)

function get_data($status){
    return $this->Data->get_data($status);
}

function view_data(){
    return view('user/view-data',['data'=>$this])
}

In Model (MyData.php)

function get_data($status="approved"){
    return $this->select()->where('status',$status)->get()->getResultArray();
}

In View (MyData.php)

$datas = $data->get_data('approved');

Error

mysqli_sql_exception #1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '*, *, *

CodePudding user response:

I believe your view_data function should be

function view_data(){
    return view('user/view-data',['data'=>$this->get_data('approved')])
}

Then in view just loop through the $data array

Views are places that you MUST NOT need to execute sql queries. You need to pass only data (objects, arrays, string, int, etc.) to views.

  • Related