Go Back   Forum Care Forums > Development Reference Area > MySQL Discussion

Reply
 
LinkBack Thread Tools Display Modes
[newbie] 4 questions about MySql5 here
Old
  (#1)
Jeff
Guest
 
Posts: n/a
Default [newbie] 4 questions about MySql5 here - 06-04-2007, 07:49 AM

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


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [newbie] 4 questions about MySql5 here
Old
  (#2)
Axel Schwenke
Guest
 
Posts: n/a
Default Re: [newbie] 4 questions about MySql5 here - 06-04-2007, 07:50 AM

"Jeff" <EMAIL REMOVED> 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/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top