RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Ryan Jameson (USA)
for MS SQL and Oracle does anyone know a more reliable way to do this than select 
max(ID) immediately after the insert? It seems silly that I'd have to take my chances 
that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Bernain, Fernando G.
This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

The information in this email is confidential and may be
legally privileged.
It is intended solely for the addressee.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure,
copying, distribution
or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice
contained in this email are subject to the terms and
conditions expressed in the governing KPMG client engagement
letter.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Ryan Jameson (USA)
This doesn't work as expected through ODBC... it does not seem to return any value...

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

The information in this email is confidential and may be
legally privileged.
It is intended solely for the addressee.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure,
copying, distribution
or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice
contained in this email are subject to the terms and
conditions expressed in the governing KPMG client engagement
letter.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Bernain, Fernando G.
You can use this inside an stored procedure, for instance:

CREATE PROCEDURE SP_INSERT_TRANSACCION
@transacfecha datetime,
@observacion char(100)
 AS
INSERT INTO Transaccion(transacfecha, observacion)
VALUES(
@transacfecha,
@observacion
)
SELECT @@IDENTITY AS 'nrotrans'
END

In this example, I insert two values with this sp in a table with and
Identity column. So, the SP return the value of the transaccion generated...
You've got the idea???


Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:36 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This doesn't work as expected through ODBC... it does not seem to return any
value...

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

The information in this email is confidential and may be
legally privileged.
It is intended solely for the addressee.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure,
copying, distribution
or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice
contained in this email are subject to the terms and
conditions expressed in the governing KPMG client engagement
letter.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Ryan Jameson (USA)
The problem is I have hundreds of tables each with a different column list and syntax, 
I don't want to have to create a SP for each table. There really has to be an easy way 
to do this. Now my sql server is saying this:

Connection is busy with results for another hstmt, SQL state S1000

. it looks like I'll have to take my chances with select max() 

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:43 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


You can use this inside an stored procedure, for instance:

CREATE PROCEDURE SP_INSERT_TRANSACCION
@transacfecha datetime,
@observacion char(100)
 AS
INSERT INTO Transaccion(transacfecha, observacion)
VALUES(
@transacfecha,
@observacion
)
SELECT @@IDENTITY AS 'nrotrans'
END

In this example, I insert two values with this sp in a table with and
Identity column. So, the SP return the value of the transaccion generated...
You've got the idea???


Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:36 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This doesn't work as expected through ODBC... it does not seem to return any
value...

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

The information in this email is confidential and may be
legally privileged.
It is intended solely for the addressee.
Access to this email by anyone else is unauthorised.
If you are not the intended recipient, any disclosure,
copying, distribution
or any action taken or omitted to be taken in reliance
on it, is prohibited and may be unlawful.
When addressed to our clients any opinions or advice
contained in this email are subject to the terms and
conditions expressed in the governing KPMG client engagement
letter.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Bernain, Fernando G.
It's not a bad idea to encapsulate de querys (selects, updates, inserts,...)
in SPs...

Good luck with the select max()!!!

PD: If you dont want/can use identitys, maybe you can use another table
where you store de next number of transaction. So its easy to update this
number (plus one) and make a select inmediatley to obtein the number... its
a bit strange but it works!!!

Buena suerte!!!

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:46 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


The problem is I have hundreds of tables each with a different column list
and syntax, I don't want to have to create a SP for each table. There really
has to be an easy way to do this. Now my sql server is saying this:

Connection is busy with results for another hstmt, SQL state S1000

. it looks like I'll have to take my chances with select max() 

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:43 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


You can use this inside an stored procedure, for instance:

CREATE PROCEDURE SP_INSERT_TRANSACCION
@transacfecha datetime,
@observacion char(100)
 AS
INSERT INTO Transaccion(transacfecha, observacion)
VALUES(
@transacfecha,
@observacion
)
SELECT @@IDENTITY AS 'nrotrans'
END

In this example, I insert two values with this sp in a table with and
Identity column. So, the SP return the value of the transaccion generated...
You've got the idea???


Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:36 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This doesn't work as expected through ODBC... it does not seem to return any
value...

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return the record ID back so that I know what the ID is.  I will later
 allow that record's information to be populated based on the ID it first
 returned.
 
 How would I do this?
 
 Thank you, thank you!
 
 Doug Coning
 
 
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Email Disclaimer

RE: [PHP-DB] Re: NewB: Return New Record ID...

2002-12-26 Thread Ryan Jameson (USA)
Ok, this does work through ODBC as 2 seperate queries. This seems like a safer way to 
do it.
I was trying to make it work as one insert query that returned the id. That was when I 
got the strange error message. Thanks!

 Ryan


-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:54 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


It's not a bad idea to encapsulate de querys (selects, updates, inserts,...)
in SPs...

Good luck with the select max()!!!

PD: If you dont want/can use identitys, maybe you can use another table
where you store de next number of transaction. So its easy to update this
number (plus one) and make a select inmediatley to obtein the number... its
a bit strange but it works!!!

Buena suerte!!!

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:46 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


The problem is I have hundreds of tables each with a different column list
and syntax, I don't want to have to create a SP for each table. There really
has to be an easy way to do this. Now my sql server is saying this:

Connection is busy with results for another hstmt, SQL state S1000

. it looks like I'll have to take my chances with select max() 

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:43 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


You can use this inside an stored procedure, for instance:

CREATE PROCEDURE SP_INSERT_TRANSACCION
@transacfecha datetime,
@observacion char(100)
 AS
INSERT INTO Transaccion(transacfecha, observacion)
VALUES(
@transacfecha,
@observacion
)
SELECT @@IDENTITY AS 'nrotrans'
END

In this example, I insert two values with this sp in a table with and
Identity column. So, the SP return the value of the transaccion generated...
You've got the idea???


Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:36 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This doesn't work as expected through ODBC... it does not seem to return any
value...

 Ryan

-Original Message-
From: Bernain, Fernando G. [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 10:09 AM
To: Ryan Jameson (USA)
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


This is from de books online (MSSQL).

@@IDENTITY (T-SQL)
Returns the last-inserted identity value. 

Syntax
@@IDENTITY

Return Types
numeric

Remarks
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY
contains the last identity value generated by the statement. If the
statement did not affect any tables with identity columns, @@IDENTITY
returns NULL. If multiple rows are inserted, generating multiple identity
values, @@IDENTITY returns the last identity value generated. If the
statement fires one or more triggers that perform inserts that generate
identity values, calling @@IDENTITY immediately after the statement returns
the last identity value generated by the triggers. The @@IDENTITY value does
not revert to a previous setting if the INSERT or SELECT INTO statement or
bulk copy fails, or if the transaction is rolled back.

Examples
This example inserts a row into a table with an identity column and uses
@@IDENTITY to display the identity value used in the new row.

INSERT INTO jobs (job_desc,min_lvl,max_lvl)

VALUES ('Accountant',12,125)

SELECT @@IDENTITY AS 'Identity'

  

Fernando Bernain
Senior A
Business Process Outsourcing

KPMG Argentina
Tel: 54 11 4316 5754
Fax: 54 11 4316 5734
[EMAIL PROTECTED]




-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 26, 2002 2:06 PM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] Re: NewB: Return New Record ID...


for MS SQL and Oracle does anyone know a more reliable way to do this than
select max(ID) immediately after the insert? It seems silly that I'd have to
take my chances that another has been inserted in between.

 Ryan

-Original Message-
From: J.Veenhuijsen [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 06, 2002 1:52 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: NewB: Return New Record ID...


Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:
 Hi all,
 
 How do I do this:
 
 I need a PHP page that simply creates a blank record so that I have the
 record's ID (which is automatically generated).  That same page then needs
 to return

[PHP-DB] Re: NewB: Return New Record ID...

2002-12-06 Thread J.Veenhuijsen
Try $last=mysql_insert_id();

Jochem

Doug Coning wrote:

Hi all,

How do I do this:

I need a PHP page that simply creates a blank record so that I have the
record's ID (which is automatically generated).  That same page then needs
to return the record ID back so that I know what the ID is.  I will later
allow that record's information to be populated based on the ID it first
returned.

How would I do this?

Thank you, thank you!

Doug Coning






--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php