如何获取上一个或下一个 ID
how to get last or next Id
使用 Jamie Rumbelow 的 My_Model 和 mySQL。我无法找到如何在特定 table 中获取最后插入的 ID。例如,
Table_A
--------+
id |
--------+
1 |
--------+
2 |
--------+
我正在尝试下面的代码,但它返回 int(0)
$id = $this->Model_teacher->_database->insert_id();
试试这个:
Returns最后插入行的ID
$con -> lastInsertId();
我找到了你正在使用的库.. https://github.com/jamierumbelow/codeigniter-base-model/blob/master/core/MY_Model.php
public function insert($data, $skip_validation = FALSE)
{
if ($skip_validation === FALSE)
{
$data = $this->validate($data);
}
if ($data !== FALSE)
{
$data = $this->trigger('before_create', $data);
$this->_database->insert($this->_table, $data);
$insert_id = $this->_database->insert_id();
$this->trigger('after_create', $insert_id);
return $insert_id;
}
else
{
return FALSE;
}
}
插入成功后,returns$insert_id;
$id = $this->Model_teacher->insert(...);
使用 Jamie Rumbelow 的 My_Model 和 mySQL。我无法找到如何在特定 table 中获取最后插入的 ID。例如,
Table_A
--------+
id |
--------+
1 |
--------+
2 |
--------+
我正在尝试下面的代码,但它返回 int(0)
$id = $this->Model_teacher->_database->insert_id();
试试这个:
Returns最后插入行的ID
$con -> lastInsertId();
我找到了你正在使用的库.. https://github.com/jamierumbelow/codeigniter-base-model/blob/master/core/MY_Model.php
public function insert($data, $skip_validation = FALSE)
{
if ($skip_validation === FALSE)
{
$data = $this->validate($data);
}
if ($data !== FALSE)
{
$data = $this->trigger('before_create', $data);
$this->_database->insert($this->_table, $data);
$insert_id = $this->_database->insert_id();
$this->trigger('after_create', $insert_id);
return $insert_id;
}
else
{
return FALSE;
}
}
插入成功后,returns$insert_id;
$id = $this->Model_teacher->insert(...);