How does the PHP PDO call stored procedure return multiple collections and output parameters?

Source: Internet
Author: User
SELECT * FROM table;
SELECT * FROM table1;
Out $id;

As above: The stored procedure returns two result sets and one output parameter, how do you get both result sets and output parameters in PHP?


Reply to discussion (solution)

Read
See Pdostatement::nextrowset method description

Read
See Pdostatement::nextrowset method description
If there are only multiple collections I know, but there are output parameters, as follows

$stmt = $db->prepare ("Call Pro_test (: Name, @sp_result);"); $stmt->execute (Array (': Name ' = $name)), $outputArray = $db->query ("select @sp_result")->fetch (PDO:: FETCH_ASSOC);p Rint_r ($outputArray ["@sp_result"]);


The stored procedure returns a collection, and the output parameter needs to be queried once, but in this step there is an error.
$outputArray = $db->query ("select @sp_result")->fetch (PDO::FETCH_ASSOC);
Error:soap-env:server, String:call to a member function fetch () on a non-object

I guess it should be. Before the stored procedure returned a result, another one on the error, how to solve?

This is an example from the manual.

$sql = ' Call Multiple_rowsets () '; $stmt = $conn->query ($sql); $i = 1;do {    $rowset = $stmt->fetchall (pdo_fetch_ NUM);    if ($rowset) {//Think about why you should first Judge        Printresultset ($rowset, $i);    }    $i + +;} while ($stmt->nextrowset ());

This is an example from the manual.

$sql = ' Call Multiple_rowsets () '; $stmt = $conn->query ($sql); $i = 1;do {    $rowset = $stmt->fetchall (pdo_fetch_ NUM);    if ($rowset) {//Think about why you should first Judge        Printresultset ($rowset, $i);    }    $i + +;} while ($stmt->nextrowset ());

You may have misunderstood me, I need the result set of the stored procedure and the parameters returned by the stored procedure, but have been solved, or go to the official website to see, thank you for your attention, • There's a lot of questions back there.
Note for mysql:to use input/output parameters for stored procedures with PDO use PDO. Query () statement. For example: 
 
   query ("CAST somestoredprocedure ($someInParameter 1, $someInParameter 2, @someOutParameter)"); $ Dbh->query ("select @someOutParameter");?> or, if you want very much to the use PDO. Prepare (), insert "Select @someOutParameter" in your stored procedure and then use: 
 
   Prepare ("CAST Somestoredproc Edure (?,?) "); $stmt->execute (Array ($someInParameter 1, $someInParameter 2));?>
  • 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.