The following article is mainly to introduce you to the PHP and MySQL stored procedures example demo, I two days in the relevant web site to see the PHP and MySQL stored procedures Examples of the information, feel very good, it was taken out for everyone to share. Hope that in the future you will be helpful in the study.
PHP and MySQL stored procedure instance one: no parameter stored procedure
$conn = mysql_connect (' localhost ', ' root ', ' root ') or Die ("Data connection error!!!");
mysql_select_db (' Test ', $conn);
$sql = " CREATE PROCEDURE Myproce () begin
INSERT into user (ID, username, sex)
VALUES (NULL, ' s ', ' 0 ');
end; ";
mysql_query ($sql);
|
To create a Myproce stored procedure
$sql = "Call Test.myproce ();";
mysql_query ($sql);
Calls the myproce stored procedure, a new record is added to the database.
PHP and MySQL Stored procedure example two: stored procedures for incoming parameters
$sql = " CREATE PROCEDURE Myproce2 (in score int)
begin If score >=
select ' Pass '; else select ' No ';
End If; end; ";
mysql_query ($sql);
|
To create a myproce2 stored procedure
$sql = "Call Test.myproce2 (70);"; mysql_query ($sql);
Call the Myproce2 stored procedure, see the effect, you can see the results under CMD.
PHP and MySQL stored procedure instance three: stored procedures for outgoing parameters
$sql = " CREATE PROCEDURE Myproce3 (out score int)
begin Set score=100; end; ";
mysql_query ($sql);
|
To create a myproce3 stored procedure
$sql = "Call Test.myproce3 (@score);"; mysql_query ($sql);
Calling Myproce3 stored Procedures
$result = mysql_query (' select @score; ');
$array = Mysql_fetch_array ($result);
Echo ' <pre> ';p rint_r ($array);
PHP and MySQL
|
Stored procedure Instance four: InOut stored procedures for outgoing parameters
$sql = " CREATE PROCEDURE Myproce4 (inout sexflag int)
begin SELECT * from user
WHERE sex = sexflag; end; ";
mysql_query ($sql);
|
To create a Myproce4 stored procedure
$sql = "Set @sexflag = 1"; mysql_query ($sql); Set the gender parameter to 1
$sql = "Call Test.myproce4 (@sexflag);"; mysql_query ($sql);
Call the Myproce4 stored procedure, see the effect under CMD