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);?>