11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 32 • STORED ROUTINESDELIMITER //CREATE PROCEDURE service_info(IN client_id INT, IN services varchar(20))BEGINDECLARE comma_pos INT;DECLARE current_id INT;svcs: LOOPSET comma_pos = LOCATE(',', services);SET current_id = SUBSTR(services, 1, comma_pos);IF current_id 0 THENSET services = SUBSTR(services, comma_pos+1);ELSESET current_id = services;END IF;INSERT INTO request_info VALUES(NULL, client_id, current_id);IF comma_pos = 0 OR current_id = '' THENLEAVE svcs;END IF;END LOOP;END//DELIMITER ;Now call service_info, like so:call service_info("45","1,4,6");Once executed, the request_info table will contain the following three rows:+-------+----------+----------+| row_id | client_id | service |+-------+----------+----------+| 1 | 45 | 1 || 2 | 45 | 4 || 3 | 45 | 6 |+-------+----------+----------+639

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!