MySQL PDO zuletzt eingegebene ID

Ich habe eine Tabelle in MySQL mit einem Primärschlüssel, die ich in diese Tabelle eingefügt habe, und ich möchte die ID der zuletzt eingefügten Zeile wieder aufnehmen. Ich weiß, dass ich sie verwenden mussLAST_INSERT_ID Aber meine Frage ist, nachdem ich diese Anweisung zum Einfügen von Werten in eine andere Tabelle ohne Primärschlüssel verwendet habe. Kann ich sie erneut verwenden, um die genaue ID der zuerst eingefügten zu erhalten?

$ 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
            ));
        }

und jetzt, wenn dieabout==place kann ich das schreiben

$query = "INSERT INTO `question-io` (questionID, io) VALUES
                (LAST_INSERT_ID() ,:io )";
$sth = $this->db->prepare($query);
$sth->execute(array(
                ':io' => $io
            ));

Ich habe es nicht probiert, weil ich es nicht probieren kann, bis ich alle meine Tabellen und ich nicht alle meine Tabellen füllen kann, ohne die ID zu kennen :)

Antworten auf die Frage(2)

Ihre Antwort auf die Frage