我正在創建模型,我想訪問控制器中的方法,但查詢給出錯誤:
mysqli_sql_exception #1064 你的 SQL 語法有錯誤;檢查與您的 MariaDB 服務器版本相對應的手冊,以在第 3 行的 ':0: AND 1 = :1: LIMIT 1' 附近使用正確的語法
我的代碼有什么錯誤?
<?php
namespace App\Models;
use CodeIgniter\Model;
class UserModel extends Model{
protected $table='users';
protected $allowedFields=['employee_name','employee_email','employee_phone','employee_dept','employee_grade','employee_password','employee_cpassword','emp_image'];
public $db;
public function __construct()
{
$this->db = \Config\Database::connect();
}
public function getEmployee($id=false)
{
if($id==null)
{
return $this->findAll();
}
return $this->where(['id',$id])->first();
}
}
控制器:
public function edit($id) {
$model = model(UserModel::class);
$data['emp']=$model->getEmployee($id);
print_r($data['emp']);
exit();
}
路線:
$routes->get('/edit/(:num)','Admin::edit/$1');
uj5u.com熱心網友回復:
更改自:
return $this->where(['id',$id])->first();
到
return $this->where('id', $id)->first();
要么
return $this->where(['id' => $id])->first();
看看這里的檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/431264.html
標籤:代码点火器
上一篇:使用PHP(Codeigniter)建立經過身份驗證的會話后如何在JavaScript中重定向到另一個網站
下一篇:Ci4/影像上傳和操作錯誤/finfo_file(/tmp/phpSrVWUZ):無法打開流:沒有這樣的檔案或目錄
