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"
Date |
Document code |
Material code |
Item Name |
Measurement unit |
Business type |
Change quantity |
"; 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"
". $ Row [" FDate "]." |
". $ Row [" FBillNo "]." |
". $ Row [" FNumber "]." |
". $ Row [" FName "]." |
". $ Row [" FUnitName "]." |
". $ Row [" FTranType "]." |
". $ Row [" FQty "]." | "; Echo"
";}}$ I ++;} while ($ stmt-> nextRowset (); echo"
";} Catch (pdoexception $ e) {print 'execution failed: '. $ e-> getMessage (); exit ();}
Try again first