[PHP-DB] getting data back when inserting

2004-12-01 Thread Aaron Todd
I was wondering if somone might be able to suggest a command to me...I am 
inserting data into a MySQL database that has an auto-incrementing primary 
field.  When I insert the data I would like to somehow get the value of the 
auto-incrementing primary field.  I thought I could just run a SELECT 
statement on some of the data that I am inserting, but the problem is that 
it could have a duplicate already in the database.

Anyone know of a command or something to point me in the direction I am 
looking to go?

Thanks,

Aaron 

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



RE: [PHP-DB] getting data back when inserting

2004-12-01 Thread Gryffyn, Trevor
I know this is only semi-helpful, but maybe it'll give you a kick in the
right direction.

In Microsoft SQL-Server you'd use @@IDENTITY to get the ID of the last
row you inserted.  There's bound to be something similar in other DB
systems.  identity is what SQL Server calls auto-number type fields,
fyi.

One thing to watch out for...  Make sure you're getting your 'local'
auto-number and not a global one.  If your script inserts something, and
someone else's script (or a different user using your script) inserts
something else, THEN you snag the ID, you could get the other user's
auto-number ID instead of the one you just inserted.

If you make sure you're getting the 'local' ID, then it'll always return
the last one that you inserted.


Another note is that usually 'local' ID is determined by database
connection session.  If you use something like ADOdb (or another
abstraction layer... Or just in general), make sure you're getting the
ID before you close your connection to the database.

Thought that could be helpful even if not specific to MySQL, the
concepts and caveats should be similar.

-TG

 -Original Message-
 From: Aaron Todd [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, December 01, 2004 11:01 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] getting data back when inserting
 
 
 I was wondering if somone might be able to suggest a command 
 to me...I am 
 inserting data into a MySQL database that has an 
 auto-incrementing primary 
 field.  When I insert the data I would like to somehow get 
 the value of the 
 auto-incrementing primary field.  I thought I could just run a SELECT 
 statement on some of the data that I am inserting, but the 
 problem is that 
 it could have a duplicate already in the database.
 
 Anyone know of a command or something to point me in the 
 direction I am 
 looking to go?
 
 Thanks,
 
 Aaron 
 
 -- 
 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] getting data back when inserting

2004-12-01 Thread Stefan
You should easily use 

mysql_insert_id();

otherwise you could use something like:

SELECT max(id) FROM ...

But I think the first command is what you're looking for.

Stefan


 -Ursprüngliche Nachricht-
 Von: Aaron Todd [mailto:[EMAIL PROTECTED]
 Gesendet: Mittwoch, 1. Dezember 2004 17:01
 An: [EMAIL PROTECTED]
 Betreff: [PHP-DB] getting data back when inserting
 
 I was wondering if somone might be able to suggest a command to me...I am
 inserting data into a MySQL database that has an auto-incrementing primary
 field.  When I insert the data I would like to somehow get the value of
 the
 auto-incrementing primary field.  I thought I could just run a SELECT
 statement on some of the data that I am inserting, but the problem is that
 it could have a duplicate already in the database.
 
 Anyone know of a command or something to point me in the direction I am
 looking to go?
 
 Thanks,
 
 Aaron
 
 --
 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] getting data back when inserting

2004-12-01 Thread Aaron Todd
Thanks a bunch...thats exactly what I was looking for.

Aaron


Stefan [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
You should easily use

mysql_insert_id();

otherwise you could use something like:

SELECT max(id) FROM ...

But I think the first command is what you're looking for.

Stefan


 -Ursprüngliche Nachricht-
 Von: Aaron Todd [mailto:[EMAIL PROTECTED]
 Gesendet: Mittwoch, 1. Dezember 2004 17:01
 An: [EMAIL PROTECTED]
 Betreff: [PHP-DB] getting data back when inserting

 I was wondering if somone might be able to suggest a command to me...I am
 inserting data into a MySQL database that has an auto-incrementing primary
 field.  When I insert the data I would like to somehow get the value of
 the
 auto-incrementing primary field.  I thought I could just run a SELECT
 statement on some of the data that I am inserting, but the problem is that
 it could have a duplicate already in the database.

 Anyone know of a command or something to point me in the direction I am
 looking to go?

 Thanks,

 Aaron

 --
 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



AW: [PHP-DB] getting data back when inserting

2004-12-01 Thread Stefan
The actual problem was the leading number in some of your arguments
(4_h_1, 4_h_2, etc)

Stefan

 -Ursprüngliche Nachricht-
 Von: Aaron Todd [mailto:[EMAIL PROTECTED]
 Gesendet: Mittwoch, 1. Dezember 2004 18:33
 An: [EMAIL PROTECTED]
 Betreff: Re: [PHP-DB] getting data back when inserting
 
 Thanks a bunch...thats exactly what I was looking for.
 
 Aaron
 
 
 Stefan [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 You should easily use
 
 mysql_insert_id();
 
 otherwise you could use something like:
 
 SELECT max(id) FROM ...
 
 But I think the first command is what you're looking for.
 
 Stefan
 
 
  -Ursprüngliche Nachricht-
  Von: Aaron Todd [mailto:[EMAIL PROTECTED]
  Gesendet: Mittwoch, 1. Dezember 2004 17:01
  An: [EMAIL PROTECTED]
  Betreff: [PHP-DB] getting data back when inserting
 
  I was wondering if somone might be able to suggest a command to me...I
 am
  inserting data into a MySQL database that has an auto-incrementing
 primary
  field.  When I insert the data I would like to somehow get the value of
  the
  auto-incrementing primary field.  I thought I could just run a SELECT
  statement on some of the data that I am inserting, but the problem is
 that
  it could have a duplicate already in the database.
 
  Anyone know of a command or something to point me in the direction I am
  looking to go?
 
  Thanks,
 
  Aaron
 
  --
  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

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



RE: [PHP-DB] getting data back when inserting

2004-12-01 Thread Bastien Koert
mysql_insert_id
bastien
From: Aaron Todd [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [PHP-DB] getting data back when inserting
Date: Wed, 1 Dec 2004 11:01:19 -0500
I was wondering if somone might be able to suggest a command to me...I am
inserting data into a MySQL database that has an auto-incrementing primary
field.  When I insert the data I would like to somehow get the value of the
auto-incrementing primary field.  I thought I could just run a SELECT
statement on some of the data that I am inserting, but the problem is that
it could have a duplicate already in the database.
Anyone know of a command or something to point me in the direction I am
looking to go?
Thanks,
Aaron
--
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