Ec (2); stored procedures and functions are just introduced by MySql5.0. This operation is not directly supported in PHP. However, due to the design of mysqlphp API, we can support calling stored procedures and functions in mysqlphp API in the previous PHP version. Call stored procedures and functions in php. 1. The method that calls the stored procedure. A. If the stored procedure has an ININOUT parameter, declare a variable and input the parameter to the stored procedure. The variable is script ec (2); script
Stored Procedures and functions are just introduced by MySql5.0. This operation is not directly supported in PHP. However, due to the design of the Mysql php api, we can support calling stored procedures and functions in the mysql PHP api of the previous php version.
Call stored procedures and functions in php.
1. The method that calls the stored procedure.
A. If the stored procedure has the IN/INOUT parameter, declare a variable and input the parameter to the stored procedure. The variable is a pair,
A php variable (or not required, but there is no way to enter the php variable dynamically), a Mysql
Variable.
B. If the stored procedure has an OUT variable, declare a Mysql variable.
The declaration of mysql variables is special. the mysql server must know the existence of this variable, that is, to execute a mysql statement.
Input set @ mysqlvar = $ phpvar;
C. Use mysql_query ()/mysql_db_query () to execute the mysql variable declaration statement.
Mysql_query ("set @ mysqlvar [= $ pbpvar ]");
In this way, there is a variable in the mysql server, @ mysqlar. If the IN parameter is used, the value can be phpar input.
D.
If the stored procedure is used.
1. Execute the call procedure () statement.
That is, mysql_query ("call proceduer ([var1]...)");
2. If a return value exists, run select @ ar to return the execution result.
Mysql_query ("select @ var )"
The next operation is the same as executing a mysql statement in php. You can use functions such as mydql_fetch_row () to obtain the result.
If the time function.
You can directly execute select function.
$ Host = "localhost ";
$ User = "root ";
$ Password = "11212 ";
$ Db = "samp_db ";
$ Dblink = mysql_connect ($ host, $ user, $ password)
Or die ("can't connect to mysql ");
Mysql_select_db ($ db, $ dblink)
Or die ("can't select samp_db ");
$ Res = mysql_query ("set @ a = $ password", $ dblink );
$ Res = mysql_query ("call aa (@ a)", $ dblink );
$ Res = mysql_query ("select @ a", $ dblink );
$ Row = mysql_fetch_row ($ res );
Echo $ row [0];