query("INSERT INTO `foo` -6ren">
cuốn sách gpt4 ai đã làm

php - 依赖 "mysql_insert_id"

In lại Tác giả: Walker 123 更新时间:2023-11-29 03:50:45 25 4
mua khóa gpt4 Nike

考虑一个名为 foo 的表,它有 id (PRIMARY & AUTO_INCREMENT) 列。我正在向该表中插入一行,挑战从此时开始。

$db->query("INSERT INTO `foo` (id, row1, ...) VALUES('', '$row1', ...)");
if (!$db->is_error && $db->last_insert_id) {
$id = $db->last_insert_id;
do_really_important_things_with_last_ID($id);
do_another_important_things_with_last_ID($id);
...
do_ ... with_last_ID($id);
do_ ... with_last_ID($id);
}

我在插入查询后立即调用它并在获取 last_insert_id 时使用准确的当前连接链接,但不知道这有什么关系(?)。

$this->dbh = @mysql_connect(.....);
...
// query function
$this->result = @mysql_query($query, $this->dbh);
...
if (preg_match("/insert/i", $query)) {
$this->last_insert_id = @mysql_insert_id($this->dbh);
}


我是否应该担心此实现依赖于 mysql_insert_id?

câu trả lời hay nhất

last_insert_id 应该是一个函数,它将返回插入的 id

function last_insert_id(){
return @mysql_insert_id();
}

if (!$db->is_error && $db->last_insert_id()) {
$id = $db->last_insert_id();
do_really_important_things_with_last_ID($id);
do_another_important_things_with_last_ID($id);
...
do_ ... with_last_ID($id);
do_ ... with_last_ID($id);
}

关于php - 依赖 "mysql_insert_id",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634903/

25 4 0
Xem sitemap của VNExpress