Getting the value of a row you just inserted

2003-10-09 Thread Dan Anderson
Is it possible to SELECT the id (indexed PRIMARY KEY AUTO_INCREMENT) of
a row that was just inserted?  I'm using PHP, I don't know if that makes
a difference?

Something like:

INSERT INTO foo (bar) VALUES (bar);
SELECT last_insert(id) FROM foo;

Also, are there any problems with using this in an environment where
you're forking processes?

Thanks in advance,

-Dan


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: Getting the value of a row you just inserted

2003-10-09 Thread Christensen, Dave
Here's the link to the on-line manual page that will help you.

http://www.mysql.com/doc/en/example-AUTO_INCREMENT.html

-Original Message-
From: Dan Anderson [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 09, 2003 5:06 PM
To: [EMAIL PROTECTED]
Subject: Getting the value of a row you just inserted


Is it possible to SELECT the id (indexed PRIMARY KEY AUTO_INCREMENT) of a
row that was just inserted?  I'm using PHP, I don't know if that makes a
difference?

Something like:

INSERT INTO foo (bar) VALUES (bar);
SELECT last_insert(id) FROM foo;

Also, are there any problems with using this in an environment where you're
forking processes?

Thanks in advance,

-Dan


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Getting the value of a row you just inserted

2003-10-09 Thread todd
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thursday 09 October 2003 06:06 pm, Dan Anderson wrote:
: Is it possible to SELECT the id (indexed PRIMARY KEY AUTO_INCREMENT) of
: a row that was just inserted?  I'm using PHP, I don't know if that makes
: a difference?
:
: Something like:
:
: INSERT INTO foo (bar) VALUES (bar);
: SELECT last_insert(id) FROM foo;
:
: Also, are there any problems with using this in an environment where
: you're forking processes?
:
: Thanks in advance,
:
: -Dan

In php you can use mysql_insert_id() to get the id of the auto_increment 
column.

See http://www.php.net/manual/en/function.mysql-insert-id.php

todd[1]
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/hd7v9xvMmfxCaFkRAsoZAJ9eL5aQf0dCHwY/nFdH5vQIny0BrgCgrcI3
V64M7/8+BnyHjJLlzYvG1C4=
=MFdB
-END PGP SIGNATURE-

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]