PHP と Zend Framework を使用して Web サイトを作成しています。データベースと通信するために sqlsrv アダプターを使用しています。挿入クエリを作成し、新しい行の ID も保存しようとしています。次のような SQL クエリを作成しました。
$db = Zend_Db_Table::getDefaultAdapter();
$id = $db->fetchOne("
INSERT INTO MyTable
(Title, CreatedBy, Created, LastUpdatedBy, LastUpdated)
SELECT 'MY Title',
UserTable.UserId,
CONVERT(datetime, '".$this->details["Created"]."', 120),
UserTable.UserId,
CONVERT(datetime, '".$this->details["LastUpdated"]."', 120)
FROM UserTable
WHERE UserName = '".$this->details["CreatedBy"]."'
SELECT CAST(SCOPE_IDENTITY() AS int) AS Id"
);
しかし、それはこのエラーを生成します:
'Zend_Db_Statement_Sqlsrv_Exception' with message 'The active result for the query contains no fields.
このエラーを回避してこのクエリを実行し、挿入された行 ID を取得するにはどうすればよいですか?