這對我來說很奇怪。因為在 codeigniter 4 中,我的一個功能在控制器中作業但在視圖中不起作用。我正在從控制器中的資料庫獲取我的資料,但是當我試圖從它顯示的視圖中獲取相同的資料時mysqli_sql_exception #1064。
示例代碼:
在控制器中 (MyData.php)
function get_data($status){
return $this->Data->get_data($status);
}
function view_data(){
return view('user/view-data',['data'=>$this])
}
在模型中 (MyData.php)
function get_data($status="approved"){
return $this->select()->where('status',$status)->get()->getResultArray();
}
在視圖中 (MyData.php)
$datas = $data->get_data('approved');
錯誤
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 '*, *, *
uj5u.com熱心網友回復:
我相信你的view_data功能應該是
function view_data(){
return view('user/view-data',['data'=>$this->get_data('approved')])
}
然后在視圖中回圈遍歷$data陣列
視圖是您不需要執行 sql 查詢的地方。您只需要將資料(物件、陣列、字串、整數等)傳遞給視圖。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397975.html
標籤:代码点火器 mysql-错误-1064 codeigniter-4
