在cakephp中最后生成id手动查询

在cakephp中最后生成id手动查询,cakephp,Cakephp,我已经在cakephp中应用了手动查询,但没有得到最后一个生成id 我的问题是 $areas = $this->Area->query("insert into areas (Area_ID,Parent_Area_ID,Area) values ('','".$Parent_Area_ID."','".$Area_name."')"); 如何获取最后一个id?试试这个 echo $this->Area->getLastInsertID(); 如果这不起作用,请查看

我已经在cakephp中应用了手动查询,但没有得到最后一个生成id

我的问题是

$areas = $this->Area->query("insert into  areas (Area_ID,Parent_Area_ID,Area) values ('','".$Parent_Area_ID."','".$Area_name."')");
如何获取最后一个id?

试试这个

echo $this->Area->getLastInsertID();
如果这不起作用,请查看类似问题,尝试以下代码:

$this->Area->getInsertID();
此处有更多详细信息:

我闻到SQL注入漏洞。。。ps,请始终提及您的确切CakePHP版本!为什么不使用模型作为包装器呢?这将使它变得更干净、更容易使用……看起来很可能,
Area\u ID
是主键——在这种情况下,您使用查询没有任何好处,代价是将自己暴露在SQL注入中,并丢失Cake的默认ORM函数——为什么不在模型上调用save?如果您使用的是CakePHP,请使用CakePHP。