@@IDENTITY is a MS SQL internal variable. MS SQL will automaticallly populate this variable with the auto inserted ID. Trick is you have to select it while it remembers this variable (otherwise it will no longer be available until your next insert with an auto id).
I'd recommend following the suggestion found on php.net regarding using exec and then your insert query and then select @@identity. Its a bit easier if you just create an insert only function which automatically retrieves the auto id. Retrieving the @@identity value is as simple as treating it like a select query.
See about getting your hands on the MSDN for SQL Server (I think its available somewhere on msdn.microsoft.com but don't quote me). It'll be able to go into a lot more details on how MS SQL wants you to interact with these types of variables...