One Stored procedure queried by mysql displays two query results. how can I display two results in PHP?

Source: Internet
Author: User
One Stored procedure queried by mysql displays two query results. how can two results be displayed in PHP? one stored procedure queried by mysql displays two query results, how to display two results in PHP -------------------------------- mysql stored procedure: ----------------------------------- begin & nbsp; declarestr mysql Query 1 Stored procedure, Display 2 query results, how to display two results in PHP?
One Stored procedure queried by mysql displays two query results. how can I display two results in PHP?
------------------------------
Mysql stored procedure:
-------------------------------
Begin
Declare strSQL varchar (3000 );
Declare beginnum int;
Declare strCount_s varchar (2000 );
/* Determine the number of pages. if it is null, 0, or null, the first page is displayed by default */
If (PageIndex is null or PageIndex = ''or PageIndex = 0)
Then
Set PageIndex = 1;
End if;
/* Determine the number of entries displayed on each page. if it is null or 0 or null, the first entry is displayed by default */
If (SplitCount = 0 or SplitCount = ''or SplitCount is null)
Then
Set SplitCount = 1;
End if;
/* Query all datasets based on conditions */
Set @ beginnum = (PageIndex-1) * SplitCount;
Set @ strSQL = concat ('select', numtype, 'from', tablename, 'where', wheretype, '', OrderBy, 'limit', @ beginnum ,',', splitCount );

PREPARE stmt from @ strSQL;
Execute stmt;
Deallocate prepare stmt;
/* Query the total data quantity based on the condition */
Set @ strCount_s = concat ('SELECT count (1) as countnum from ', tablename, 'where', wheretype );
Prepare select_rowscount from @ strCount_s;
Execute select_rowscount;
Deallocate prepare select_rowscount;

End

MYSQL result 1: deallocate prepare stmt; all query data output
MYSQL result 2: deallocate prepare select_rowscount; total number of output queries
----------------------------------------

PHP stored procedure

----------------------------------------
/**
* Stored procedure operations
*
* @ Param $ produceAndParams name and parameters of the stored procedure
* The format is ProduceName (para1, para2 .....),
* If the parameter is a character, enclose it in single quotation marks.
* @ Return $ number of rows affected by the successful return operation of resultnum
* @ Throws Exception: the stored procedure is abnormal.
*/
Public static function RunProduce ($ produceAndParams)
{
Global $ _ config;
If (! Mysql_query ("set names". $ _ config ['coding'], self: $ _ wdbConn )){
Throw new Exception ("set character set". $ _ config ['coding']. "failed:". mysql_error ());
}
If (! Mysql_query ('call'. $ produceAndParams. ';', self: $ _ wdbConn )){
Throw new Exception ("failed to call the stored procedure:". mysql_error ());
}
$ ResultNum = mysql_affected_rows (self: $ _ wdbConn );
Return $ resultNum;
}

----------------------------------

How can I write data in PHP to display the two results of stored procedure queries?



------ Solution --------------------
For more information, see:


PHP code
Php calls MySQL stored procedure method set Type 1: call the method with input and output parameters view plainprint? $ 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 from the storage Variable type 2 output in the process: Call the view plainprint method with multiple output types and multiple input type parameters? $ 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.'
'; // Output the echo 'user id:'. $ uId from the output variable in the stored procedure; // obtain the User id Type 3: Call the view plainprint method with the returned result set? 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 dataset} catch (Exception $ e) {echo $ e;} Type 4: call a method with multiple result sets returned (currently, only mysqli can be used for implementation ~~~~~) View plainprint? // 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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.