mysql| Stored Procedures | functions
Stored procedures and functions are just introduced by MySql5.0. There is no direct support for this operation in PHP. But because of the design of the MySQL PHP API, we can support stored procedures and function calls in the MySQL PHP API in previous versions of PHP.
Call stored procedures and functions in PHP.
1. The method that invokes the stored procedure.
A. If the stored procedure has a in/inout parameter, declares a variable, enters the parameter to the stored procedure, and the variable is a pair of
A PHP variable (also can not be, just do not have PHP variables when there is no way to dynamic input), a MySQL
Variable.
B. If the stored procedure has an out variable, declare a MySQL variable.
MySQL variable declaration is more special, you must let the MySQL server know the existence of this variable, in fact, is the implementation of a MySQL statement.
into 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 time in parameter, then its value can have phpar passed in.
D. If the stored procedure is.
1. Executes the call procedure () statement.
That is mysql_query ("Call Proceduer ([var1] ...)");
2. If there is a return value, execute the Select @ar and return the execution result.
mysql_query ("Select @var)"
The next action is the same as PHP executing a general MySQL statement. Results can be obtained through functions such as Mydql_fetch_row ().
If the time function. It is OK to execute the Select function directly ().
$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];
Turn from: Dynamic Network production guide www.knowsky.com