我對 CI 框架很陌生。我正在做一個項目,一切都很順利,直到我嘗試用表格編輯數(shù)據(jù)庫中的一行。我收到這個錯誤消息:調(diào)用未定義的方法 CI_DB_mysqli_driver::prepare()這是我的控制器中的代碼。 public function edit($id) { $alimente = $this->db->query('select alimente.id, alimente.name FROM alimente WHERE id = "' . $id . '" order by name desc')->result(); $content = $this->parser->parse('alimente/edit_alimente', array("ALIMENTE" => $alimente), true); $TITLE = "Modifica"; $array = array('TITLE' => $TITLE, 'CONTENT' => $content); $this->parser->parse('TEST', $array, false);}public function edit_done() { $name = $this->input->post("name"); $id = $this->input->post("id"); $query = $this->db->prepare("update alimente set name = '" . $name . "' where id = '" . $id . "'")->result(); $query->execute($name, $id); redirect("alimente");這是我的視圖文件<form method="post" action="{SITE_URL}/alimente/edit_done"> <div class="form-group"> {ALIMENTE} <label> Id aliment</label> <input type="text" name="id" value= "{id}" readonly="true"class="form-control" /> <label> Nume aliment</label> <input type="text" name="name" value= "{name}" class="form-control" /> <br> {/ALIMENTE} </div> <input type="submit" value="Modifica" name=" modifica" class="btn btn-primary" /> </form>如果我更改準(zhǔn)備查詢最終結(jié)果是布爾值但發(fā)生編輯,我會收到此錯誤消息消息:在布爾值上調(diào)用成員函數(shù) result()
1 回答

長風(fēng)秋雁
TA貢獻(xiàn)1757條經(jīng)驗 獲得超7個贊
由于 CodeIgniter 不支持預(yù)處理語句,您可以像這樣修改代碼以使用 PDO 對象來運(yùn)行您的預(yù)處理語句:
public function edit_done() {
$name = $this->input->post("name");
$id = $this->input->post("id");
$query = $this->db->conn_id->prepare('update alimente set name = ? where id = ?');
$query->execute($name, $id);
redirect("alimente");
- 1 回答
- 0 關(guān)注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消