When it comes to databases without stored procedures, it is definitely not feasible. Below we simply write two stored procedures and then the previous database.
1 without output parameters (Add User)
Drop Procedure If Exists Proc_add;
Create Procedure Proc_add (UID Varchar ( 50 ), PWD Varchar ( 20 ), Name Varchar ( 20 ))
Begin
Insert Into T_user (u_uid, u_pwd, u_name) Values (UID, PWD, name );
End ;
Call proc_add ( ' ABCD ' , ' 123 ' , ' User 1 ' );
Select * From T_user;
Notes:
@ Is not required for Variable @
The "()" after the stored procedure name is required. Even if there is no parameter, "()" is required.
Do not add the as keyword
If the Stored Procedure contains multiple MySQL statements, the begin end keyword is required.
The semicolon ";" must be added at the end of each statement in the stored procedure.
You cannot use the "return" keyword in the MySQL stored procedure.
2. Stored Procedures with output parameters (user login)
Drop Procedure If Exists Proc_login;
Create Procedure Proc_login (
UID Varchar ( 50 ),
PWD Varchar ( 20 ),
Out back Int -- 0 failed 1 succeeded
)
Begin
Select U_uid From T_user Where U_uid = UID And U_pwd = PWD;
Set @ Rowcount = Found_rows ();
If ( @ Rowcount > 0 ) Then
Set Back = 1 ;
Else
Set Back = 0 ;
End If ;
End ;
Call proc_login ( ' Admin ' , ' 123 ' , @ B );
Select @ B As BBB;
Return the number of rows in the Select Operation. Use the found_rows () function; Use the row_count () function for the number of rows affected by the insert, update, and delete operations.