Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 24, 2012, 12:14:29 PM

Pages: [1]   Go Down
  Print  
Author Topic: Stored Procedures in mySQL  (Read 2541 times)
scribbly
Space Explorer
***
Offline Offline

Posts: 9


« on: January 17, 2011, 03:45:08 AM »

please forgive this very noob question, but I'm lost....

My intention is to create pivot tables on my tables. The tutorial I'm working from uses stored procedures, but for the life of me I can't see where I can create these?

Or is it all done in php? I would have thought that using the DB would have given better performance??

Logged
Lunartique
Intergalactic Cowboy
*****
Offline Offline

Posts: 52


LUNAFIL


WWW
« Reply #1 on: February 01, 2011, 11:17:14 AM »

To create pivot tables in PHP please go through this link: http://gonzalo123.wordpress.com/2010/01/24/pivot-tables-in-php/

A stored procedure is a procedure (like a subprogram in a regular computing language) that is stored (in the database). Correctly speaking, MySQL supports "routines" and there are two kinds of routines: stored procedures which you call, or functions whose return values you use in other SQL statements the same way that you use pre-installed MySQL functions like pi(). I'll use the word "stored procedures" more frequently than "routines" because it's what we've used in the past, and what people expect us to use.

A stored procedure has a name, a parameter list, and an SQL statement, which can contain many more SQL statements. There is new syntax for local variables, error handling, loop control, and IF conditions. Here is an example of a statement that creates a stored procedure.

CREATE PROCEDURE procedure1                /* name */
(IN parameter1 INTEGER)                    /* parameters */
BEGIN                                      /* start of block */
  DECLARE variable1 CHAR(10);                /* variables */
  IF parameter1 = 17 THEN                    /* start of IF */
    SET variable1 = 'birds';                   /* assignment */
  ELSE
    SET variable1 = 'beasts';                  /* assignment */
  END IF;                                   /* end of IF */
  INSERT INTO table1 VALUES (variable1);    /* statement */
END                                       /* end of block */

What I'm going to do is explain in detail all the things you can do with stored procedures. We'll also get into another new database object, triggers, because there is a tendency to associate triggers with stored procedures.
Logged
scribbly
Space Explorer
***
Offline Offline

Posts: 9


« Reply #2 on: February 01, 2011, 08:09:51 PM »

What I'm going to do is explain in detail all the things you can do with stored procedures. We'll also get into another new database object, triggers, because there is a tendency to associate triggers with stored procedures.

That sounds perfect: thanks!
Logged
kwills
Guest
« Reply #3 on: May 11, 2011, 06:14:47 AM »

Thank you for the link, I was actually looking for how to do exactly that myself!
Logged
smartkathy
Trekkie
**
Offline Offline

Posts: 17


« Reply #4 on: January 18, 2012, 04:44:05 AM »

Hey,

Besides the useful link already provided by the above poster, you could also check out phplens.com for more information, if you require.
Cheers.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: