This is a discussion on [newbie] 4 questions about MySql5 here within the MySQL Database forums, part of the Database Forums category; Hey I'm trying to write my first stored procedure in MySql5 (I have some experience with MS Sql Server), ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hey
I'm trying to write my first stored procedure in MySql5 (I have some experience with MS Sql Server), but before I begin I have some questions I would like to have an answer to: Question 1: Sql Server has the automatic variable @@error, which if greater than 0 means the last sql statement failed. What is equivalent at MySql5? Question 2: Sql Server has the automatic variable @@row, which tells how many rows was effected by last sql statement. What is equivalent at MySql5? Question 3: A MySql5 stored procedure can have OUT parameter, but it can also have a RETURN parameter. Is there some guidelines on which to use? Lets says I have a stored procedure that should send back to my php application the id of the last inserted primary key in the database.. Should I then use OUT or RETURN?.. Question 4: I've read in the MySql5 documentation that mysql_insert_id() returns the last inserted id. But do this mean the last inserted id in current transaction or is it the absolute last id (may return the id caused by a transaction initiated by another user)??? I have to write a stored procedure which insert a new record into a table and then sends back to my php application the id of this record... Jeff |
|
|||
|
"Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote:
> Sql Server has the automatic variable @@error, which if greater than 0 means > the last sql statement failed. What is equivalent at MySql5? No idea. Why do you need this? Declare a handler instead. > A MySql5 stored procedure can have OUT parameter, but it can also have a > RETURN parameter. Is there some guidelines on which to use? If you have only one return value, you should return it with RETURN. Otherwise you have to use OUT parameters. > I've read in the MySql5 documentation that mysql_insert_id() returns the > last inserted id. But do this mean the last inserted id in current > transaction or is it There are multiple ways to get the last generated AUTO_INCREMENT value. mysql_insert_id() is answered by the client itself (using the buffered result from the last query). LAST_INSERT_ID() is a SQL function that uses the remembered value from the last AUTO_INCREMENTed column. This is not the same! Check the manual: http://dev.mysql.com/doc/refman/5.0/...unique-id.html http://dev.mysql.com/doc/refman/5.0/...insert-id.html http://dev.mysql.com/doc/refman/5.0/...increment.html XL -- Axel Schwenke, Support Engineer, MySQL AB Online User Manual: http://dev.mysql.com/doc/refman/5.0/en/ MySQL User Forums: http://forums.mysql.com/ |