Ask a question about calling the MSSQL stored procedure with parameters and returning the result set-php Tutorial

Source: Internet
Author: User
For more information, see the following code:
If ($ debug = 1) {echo "database connection successful!
";}
Try {
$ Db-> exec ("SET names GB2312 ");
$ Stmt = $ db-> execute ("call xyyh_stock_inventory 'r99. 33569-0000-00 '");
// $ Stmt-> bindParam (1, $ FNumber );
// Call the stored procedure
$ Stmt-> execute ();
}
Catch (pdoexception $ e ){
Print 'execution failed: '. $ e-> getMessage ();
Exit ();
}
The MSSQL stored procedure I have called has been debugged. I can return the expected results in SQL query analysis. how can I write code to return the result set in PHP?
I checked the relevant information on the internet. I was dumb and didn't figure out the desired result set.


Reply to discussion (solution)

$ Stmt-> execute ();
What is returned?

PDOStatement Object ([queryString] => call xyyh_stock_inventory? )

Modified the code again,
If ($ debug = 1) {echo "database connection successful!
";}
Try {
$ Db-> exec ("SET names GB2312 ");
$ Stmt = $ db-> prepare ("call xyyh_stock_inventory: FNumber ");
$ Stmt-> bindParam (": FNumber", $ FNumber, PDO: PARAM_STR );
If ($ stmt-> execute () {echo "execution successful!
";} Else {echo" execution failed!
";}
}
Catch (pdoexception $ e ){
Print 'execution failed: '. $ e-> getMessage ();
Exit ();
}
And run the command. The result shows that the execution fails at $ stmt-> execute ().

The best solution is found

If ($ debug = 1) {echo "database connection successful!
";} Try {$ stmt = $ db-> prepare ('exec xyyh_stock_trantype_1_24? '); $ Stmt-> bindParam (1, $ FNumber); $ stmt-> execute (); if ($ debug = 1) {print_r ($ stmt); echo"
";}$ I = 1; echo"

"; Do {$ rowset = $ stmt-> fetchall (PDO: FETCH_ASSOC); if ($ rowset) {if ($ debug = 1) {print_r ($ rowset ); echo"";}If ($ debug = 1) {print_r ($ rowset [$ I]); echo"";} Foreach ($ rowset as $ row) {echo" "; Echo" "; Echo" ";}}$ I ++;} while ($ stmt-> nextRowset (); echo"
Date Document code Material code Item Name Measurement unit Business type Change quantity
". $ Row [" FDate "]." ". $ Row [" FBillNo "]." ". $ Row [" FNumber "]." ". $ Row [" FName "]." ". $ Row [" FUnitName "]." ". $ Row [" FTranType "]." ". $ Row [" FQty "]."
";} Catch (pdoexception $ e) {print 'execution failed: '. $ e-> getMessage (); exit ();}


Try again first

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.