pjordanna
asked on
get @@identity of last inserted id with out using mssql built in functions
Hi I am trying to get the indentitiy back of the last inserted id, I am having issues installing the mssql extension and need an alternative without using the mssql built in functions. Can any one help? My example code is below. Thanks
<?php
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
$connStr = "Provider=SQLOLEDB;User ID=****;Password=****;Initial Catalog=****;Data Source=****";
$conn->open($connStr);
$query = "SET NOCOUNT ON INSERT INTO
carhire_orders(
BookingID,
OrderDate)
VALUES(
'$bookingID',
'$orderDate') SELECT @@IDENTITY AS NewID SET NOCOUNT OFF";
$conn->execute($query);
// echo last inserted id
$conn->Close();
$conn = null;
?>
ASKER
Hi thanks for you reply, but I sorted it.
$conn->execute($query);
echo $rs->Fields(0); // this was the part i was stuck on for some reason...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT SCOPE_IDENTITY() as [NewID]
instead of
SELECT @@IDENTITY AS NewID
(unless you use sql 7...)
anyhow, what problems do you actually run into?