Use PHP to operate Mysql stored procedures

Source: Internet
Author: User
MySQL stored procedure is a new feature added from MySQL5.0. The main advantages of stored procedures are execution efficiency and SQL code encapsulation. Especially for SQL code encapsulation, especially when the business logic is complex. Now with the MySQL stored procedure, the... MySQL stored procedure is a new feature that has been added since MySQL 5.0. The main advantages of stored procedures are execution efficiency and SQL code encapsulation. Especially for SQL code encapsulation, especially when the business logic is complex. With the MySQL stored procedure, the business logic can encapsulate the stored procedure, which is not only easy to maintain, but also highly efficient in execution.

 ";}// Create the storage structure mysql_query (" drop procedure if exists 'My _ test1'; ", $ link ); $ create_pro_ SQL = "create procedure 'My _ test1' (a INT, B INT) BEGINDECLARE c INT; IF a IS NULL THEN SET a = 0; END IF; IF B is null then set B = 0; end if; SET c = a + B; SELECT c as sum; END; "; mysql_query ($ create_pro_ SQL, $ link) or die ("Query Invalid :". mysql_error (); // method 1 of the stored procedure execution // $ run_pro_ SQL = "CALL my_test1 ();"; // method 2 of the stored procedure execution mysql_quer Y ("SET @ a = 1", $ link); mysql_query ("SET @ B = 2", $ link); $ run_pro_ SQL = "CALL my_test1 (@, @ B); "; // execute the stored procedure $ result = mysql_query ($ run_pro_ SQL, $ link) or die (" Query Invalid :". mysql_error (); // Get the returned value $ row = mysql_fetch_row ($ result); echo $ row [0]; // 3 // close the connection mysql_close ($ link);?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.