Php calls mysql stored procedures and functions. Stored procedures and functions are just introduced in MySQL 5.0 (the best combination with PHP. This operation is not directly supported in php (as the mainstream development language. However, stored procedures and functions are just introduced in MySQL (the best combination with PHP) 5.0. This operation is not directly supported in php (as the mainstream development language. However, because of the design of MySQL (the best combination with PHP) php (as the mainstream development language) API, we can use php (as the mainstream development language) in the past) in MySQL (the best combination with PHP), php (as the mainstream development language) APIs support calling stored procedures and functions.
Call stored procedures and functions in php (as the mainstream development language.
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 (as the current mainstream development language) (or not required, but there is no way to dynamically input it when it does not have a php variable (as the current mainstream development language ), one MySQL (the best combination with PHP)
Variable.
B. If the stored procedure has an OUT variable, declare a MySQL (the best combination with PHP) variable.
The declaration of MySQL (the best combination with PHP) variables is special. the MySQL (the best combination with PHP) server must know the existence of this variable, in fact, it is to execute a MySQL (the best combination with PHP) statement.
Input set @ MySQL (the best combination with PHP) var = $ php (as the mainstream development language) var;
C. Use MySQL (the best combination with PHP) _ query ()/MySQL (the best combination with PHP) _ db_query () to execute MySQL (the best combination with PHP) variable declaration statement.
MySQL (the best combination with PHP) _ query ("set @ MySQL (the best combination with PHP) var [= $ pbpvar ]");
In this way, there is a variable in the MySQL (the best combination with PHP) server, @ MySQL (the best combination with PHP) ar. If the IN parameter is used, the value can be input IN php (as the mainstream development language) ar.
D. If the stored procedure is used.
1. Execute the call procedure () statement.
That is, MySQL (the best combination with PHP) _ query ("call proceduer ([var1]...)");
2. if a return value exists, run select @ ar to return the execution result.
MySQL (best combination with PHP) _ query ("select @ var )"
The subsequent operations are the same as php (as the mainstream development language) executing general MySQL (the best combination with PHP) statements. 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 (the best combination with PHP) _ connect ($ host, $ user, $ password)
Or die ("cant connect to MySQL (the best combination with PHP )");
MySQL (best combination with PHP) _ select_db ($ db, $ dblink)
Or die ("cant select samp_db ");
$ Res = MySQL (the best combination with PHP) _ query ("set @ a = $ password", $ dblink );
$ Res = MySQL (the best combination with PHP) _ query ("call aa (@ a)", $ dblink );
$ Res = MySQL (the best combination with PHP) _ query ("select @ a", $ dblink );
$ Row = MySQL (the best combination with PHP) _ fetch_row ($ res );
Echo $ row [0];
Parse (the best combination with PHP) 5.0 was just introduced. This operation is not directly supported in php (as the mainstream development language. But...