我有一个带有主键的MySQL表,我插入到那个表中,我想恢复最后一行的id已插入,我知道我必须使用LAST_INSERT_ID
但我的问题是在使用该语句将值插入到另一个没有主键的表后,我可以再次使用它来获取第一个插入的确切ID吗?
$php pdo#
include_once 'type_model.php';
$t = new Type_Model();
$typeID = $t->getTypeID($type);
include_once 'informationObject_model.php';
$i = new InformationObject_Model();
$answerIoID = $i->getIOID($ioAnswer);
$query = "INSERT INTO question (info, text, answer, answerIoID, firstChoice, secondChoice, thirdChoice,
firstHint, secondHint, typeID) VALUES (:info, :text, :answer, :answerIoID,
:firstChoice, :secondChoice, :thirdChoice, :firstHint, :secondHint, :typeID)";
$sth = $this->db->prepare($query);
$sth->execute(array(
':info' => $info,
':text' => $text,
':answer' => $answer,
':answerIoID' => $answerIoID,
':firstChoice' => $choices[0],
':secondChoice' => $choices[1],
':thirdChoice' => $choices[2],
':firstHint' => $hints[0],
':secondHint' => $hints[1],
':typeID' => $typeID
));
if ($about == "Place") {
include_once 'place_model.php';
$p = new Place_Model();
$placeID = $p->getPlaceID($place);
$query = "INSERT INTO `question-place` (questionID, placeID) VALUES
(LAST_INSERT_ID() ,:placeID )";
$sth = $this->db->prepare($query);
$sth->execute(array(
':placeID' => $placeID
));
}
现在,如果关于==地方可以写这个吗?
$query = "INSERT INTO `question-io` (questionID, io) VALUES
(LAST_INSERT_ID() ,:io )";
$sth = $this->db->prepare($query);
$sth->execute(array(
':io' => $io
));
我没有尝试过,因为我无法尝试,直到我填写所有表格而且我无法填写所有表格而不知道ID ?