Jump to content
Larry Ullman's Book Forums

Recommended Posts

I have a couple of questions regarding stored functions.

 

1. Where are they stored? (Can I see a stored function using phpMyAdmin or mysql client? If yes, how?)

 

2. Will the stored functions be available for as long as database exists, or only for the duration of the current database connection? (To rephrase it, should a custom function be stored just once, or it should be recreated every time the script runs?)

 

Thank you for help, as always!

Link to comment
Share on other sites

It's called procedure, and is stored as a table. It's callable, and can be parameterized. It can therefor be great for calculations or similar tasks. You just got to look it up in the manual for syntax, but now you know when you can utilize it.

 

As a side note, I've never used stored procedures myself, as tasks can often be solved other ways. It is a good trick to add to the toolbox non the less.

  • Upvote 2
Link to comment
Share on other sites

Thanks, Antonio - but here's what' I want to know:

 

1. How can I see the stored function (procedure)? For example, I'm accessing the database where I've just stored a function (using phpMyAdmin), and I only see tables that had been there previously, bot no stored function. Should I I do anything special to see that table where the function is stored?

 

2. That stored function - am I correct to assume that once the function (procedure) had been stored, it will be available anytime as long as the database exists (that it. it doesn't have to be stored again whenever database connection is established from PHP)?

Link to comment
Share on other sites

1) The phpMyAdmin interface sometimes differs quite a bit from version to version, but generally, there is a + sign in your DB structure view that you can click to see all the stored procedures you have created for that DB. Also, you can do the following:

http://stackoverflow.com/questions/5989978/how-to-list-view-stored-procedure-in-phpmyadmin

 

With that said, I used to use only stored procedures (because they are admittedly quite nice and speed things up), but phpMyAdmin support for them is weak and I also found that a lot of hosting companies will not allow you to create stored procedures from their phpMyAdmin interface, thus making all of the above moot anyway.

Nowadays, I use only prepared statements (usually with a custom-made API for ease of use), as they provide the same level of security as stored procedures, but everything is run on the PHP side, so support from hosting companies is not an issue.

 

2) Yes, the stored procedure (it's never called a stored function, as Antonio already stated), will forever exist in the DB. In other words, you create it once, and it's forever available in the DB, which is quite nice, I agree.

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...