Jump to content

writing stored procedure in mysql

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
Hello there. In order to improve speed of my php code, I would like to rewrite it to an MySQL Stored Procedure, is there anyone who can help med with this? is it even possible to do?

what I want to do is this, written in some kind of pseudocode

for each post in table x

   select * from table y where y.id=x.yid

   if match not found

       insert into y

   else

       if x.value = y.value

           update y set y.date = now();

       else 

           update y set y.value = x.value

        endif

    endif

endfor 


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Yes, that is possible. It doesn't look like the code in PHP will slow your script down that much though. In my experience (working with DBs and PHP), PHP is always faster to execute conditional statements than using the database to execute these statements.

Here is a guide that will help you write your stored procedure though: MySQL :: MySQL 5.0 Reference Manual :: 18 Stored Procedures and Functions

#3
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
yepp, that is the very manual, yes
unfortunately, it doesn't really explain how you really make them work

i guess i would need an sp for dummies or an howto-sp-file about it instead, which describes sp from the user perspective rather from the database perspective.

any suggestions of anything online?