Bluehost.com Web Hosting $6.95

[newbie] 4 questions about MySql5 here

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), ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-21-2007
Jeff
 
Posts: n/a
Default [newbie] 4 questions about MySql5 here

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


Reply With Quote
  #2 (permalink)  
Old 01-22-2007
Axel Schwenke
 
Posts: n/a
Default Re: [newbie] 4 questions about MySql5 here

"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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:23 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0