【发布时间】:2023-04-05 19:49:05
【问题描述】:
我的模型上有这个功能。
function agent_claim($agentcode,$bankname, $accowner, $accnumber){
$result= $this->db->query("INSERT INTO account (bank, number,name) VALUES ('$bankname', '$accnumber', '$accowner');");
$accid= $this->db->query("SELECT LAST_INSERT_ID();")->result();
$result = $this->agent_account($agentcode, $accid);
return result;
}
此查询的返回值必须是单个值。
$accid= $this->db->query("SELECT LAST_INSERT_ID();")->result();
我不能用这种语法插入
$result = $this->agent_account($agentcode, $accid);
因为返回值不是数字而是数组。 如何获取 $accid 的值?
【问题讨论】:
-
$this->db->query("SELECT LAST_INSERT_ID();")->row();在这里尝试 row() 而不是 result()。你应该使用 $this->db->insert_id() 来获取最后一个插入 ID。也使用活动记录进行插入。
标签: arrays codeigniter model