Type one: calling methods with input and output type parameters
Copy Code code as follows:
$returnValue = ';
try {
mysql_query ("Set @Return");
$spname = ' p__test_getinfo1 ';
mysql_query ("Call $spname (@Return, ' {$userId} ', ' {$pwd} ')") or Die ("[$spname]query failed:". Mysql_error ());
$result _return = mysql_query ("select @Return");
$row _return = mysql_fetch_row ($result _return);
$returnValue = $row _return [0];
catch (Exception $e) {
Echo $e;
}
Echo $returnValue; Output variables from the stored procedure
type two: calling methods with multiple output types and multiple input type parameters
Copy Code code as follows:
$userId = 0;
try{
mysql_query ("Set @Message");
mysql_query ("Set @Id");
mysql_query ("Call P__test_login (@Message, @Id, ' {$userId} ', ' {$pwd} ')", $conn) or Die ("Query failed:". Mysql_error ());
$result _mess = mysql_query ("select @Message");
$result _uid = mysql_query ("select @Id");
$row _mess = mysql_fetch_row ($result _mess);
$row _uid = mysql_fetch_row ($result _uid);
$Proc _error = $row _mess[0];
$uId = $row _uid[0];
}
catch (Exception $e)
{
Echo $e;
}
Echo ' proc return message: ' $Proc _error. ' <br/> '; Output variables from the stored procedure
echo ' User ID: '. $uId; Get User ID
type three: Calling a method with a return result set
Copy Code code as follows:
try {
$spname = ' P__test_getdata ';
$query = mysql_query ("Call $spname ()", $conn) or Die ("[$spname]query failed:". Mysql_error ());
while ($row = Mysql_fetch_array ($query)) {
echo $row [' Provinceid ']. ':: '. $row [' Provincename ']; Output data Set
}
catch (Exception $e) {
Echo $e;
}
Type IV: Calls a method with return multiple result sets (currently only implemented through MYSQLI ~ ~)
Copy Code code as follows:
Php
$rows = Array ();
$db = new Mysqli ($server, $user, $PSD, $dbname);
if (Mysqli_connect_errno ()) {
$this->message (' Can not connect to MySQL server ');
}
$db->query ("SET NAMES UTF8");
$db->query ("SET @Message");
if ($db->real_query ("Call P__test_getdata2 (@Message)")) {
do{
if ($result = $db->store_result ()) {
while ($row = $result->fetch_assoc ()) {
Array_push ($rows, $row);
}
$result->close ();
}
}while ($db->next_result ());
}
$db->close ();
Print_r ($rows);
Procedure
......
SELECT * FROM T1 where ...
SELECT * FROM T2 where ...
......