Obtaining a RecordSet when INSERTING

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EvanClark
Forum Newbie
Posts: 9
Joined: Thu Aug 22, 2002 1:36 am
Contact:

Obtaining a RecordSet when INSERTING

Post by EvanClark »

Hey Guys ...

Is it possible to make MySQL return a RecordSet when INSERTing data into a table.

For example:

2 data fields - ID (autoincrement int), name (varchar)

Lets say, I execute "INSERT INTO TABLE (name) VALUES ('Evan');"

However, now I must say "SELECT ID FROM TABLE WHERE name='Evan';" in order to find out what ID value was assigned to the new name entry. And if another 'Evan' has been entered into the table, it gets even more complex.

Does anyone know of a way to get MySQL to return a RecordSet based on what was just inserted into the table?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Use the function mysql_insert_id() for something like that.
EvanClark
Forum Newbie
Posts: 9
Joined: Thu Aug 22, 2002 1:36 am
Contact:

Post by EvanClark »

Thanks Jason.

I've been programming PHP for 2.5 years now and I'd never heard of that function before. :D
EvanClark
Forum Newbie
Posts: 9
Joined: Thu Aug 22, 2002 1:36 am
Contact:

Post by EvanClark »

I know I'll probably get black-listed :twisted: for this question but here goes ...


Does anyone know the ASP/MS-SQL equivalent to mysql_insert_id()?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

I honestly don't think ASP/MS-SQL has that same thing? I am not surprised though. Show me ASP's mail() function, or how I can do uploads in ASP. :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

MSDN provides sample code for file-upload in ASP/VBscript.
You can't imagine how slow it is :(
But mail support is available. You have to use some COM-Objects but they are quite charming - a little bit overkill for a simple "Done." mail but handy if you have to create more complex mails
EvanClark
Forum Newbie
Posts: 9
Joined: Thu Aug 22, 2002 1:36 am
Contact:

Post by EvanClark »

To be fair to the ASP/MS-SQL combination ... atleast they have got Stored Procedures.

I'd sell my first born child for MySQL to have Stored Procedures. :twisted:
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

How much would you be selling this child for? :)
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

ditch mysql and use postgresql, it takes a while but pgsql has a lot more to offer than mysql

(including stored procedures, functions and types + transactions...)

check http://www3.us.postgresql.org/ for more info

-9902468
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

And yet, PostgreSQL lacks some serious things also needed in a business environment.

I tried doing a search for replication, and found nothing. I couldn't keep looking. MySQL has it, and PostgreSQL doesn't, and we need it.
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

I guess it is not perfect, but in my case (No replication needed) I value transactions over mysql speed.


-VV
Post Reply