私はこのようなものを持っています:
$stmt = $this->getDoctrine()->getConnection()->prepare(
'insert into someTable (columnList) values (parameters);');
/*
bind parameters
*/
$stmt->execute();
最後に挿入された ID を取得するにはどうすればよいですか?
ありがとう、スコット
私はこのようなものを持っています:
$stmt = $this->getDoctrine()->getConnection()->prepare(
'insert into someTable (columnList) values (parameters);');
/*
bind parameters
*/
$stmt->execute();
最後に挿入された ID を取得するにはどうすればよいですか?
ありがとう、スコット
lastInsertId() を使用する必要があります。
例:
$dbh = Doctrine_Manager::getInstance()->getCurrentConnection();
$sth = $dbh->prepare("INSERT INTO continent (created_at, updated_at) VALUES ( NOW(), NOW() )");
$sth->execute();
$conn = Doctrine_Manager::getInstance()->getCurrentConnection();
$conn->lastInsertId('continent_id');
以下のコードは、質問に正しく答えます。
//This call will get the doctrine connection from inside a symfony2 controller
$conn = $this->getDoctrine()->getConnection();
$stmt = $conn->prepare(
'insert into someTable (columnList) values (parameters);');
/*
bind parameters
*/
$stmt->execute();
$id = $conn->lastInsertId();
作成した doctrine リポジトリ クラス内から接続を取得するには:
$conn = $this->getEntityManager()->getConnection();