Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこのコードを持っています
if($pdo instanceof PDO){ $this->last = 'lastInsertId'; } else{ $this->last = 'insert_id'; }
データベースで挿入クエリを実行すると、最後に挿入された ID を取得するにはどうすればよいですか。私はこのようにしてみました
$this->db->{$this->last};
しかし、うまくいきませんでした。
事前に助けてくれてありがとう。
lastInsertIdはメソッドであるため、プロパティ/フィールドとしてではなく、メソッドとして呼び出す必要があります。
lastInsertId
$this->db->{$this->last}();