在jquery-file-upload中,当“position”的DB值等于“id”时,如何插入数据,谢谢
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `title`, `description`, `position`)'
.' VALUES (?, ?, ?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
'sisssi',
$file->name,
$file->size,
$file->type,
$file->title,
$file->description,
$file->position
);
$query->execute();
$file->id = $this->db->insert_id;
}
return $file;
最佳答案
您应该分两步完成:
if (empty($file->error)) {
$sql = 'INSERT INTO `'.$this->options['db_table']
.'` (`name`, `size`, `type`, `title`, `description`)'
.' VALUES (?, ?, ?, ?, ?)';
$query = $this->db->prepare($sql);
$query->bind_param(
$file->name,
$file->size,
$file->type,
$file->title,
$file->description
);
$query->execute();
$file->id = $this->db->insert_id;
$sql = 'UPDATE `'.$this->options['db_table']
.'` SET `position` = `id` WHERE `id` = ?';
$query = $this->db->prepare($sql);
$query->bind_param(
$file->id
);
$query->execute();
}
return $file;
首先插入没有位置,然后根据最后插入的id更新位置。
关于php - 当jquery-file-upload中的DB值 "position"等于 "id"时,如何插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26445239/