Getting output of MS stored proc on php call (sqlsrv)

后端 未结 2 370
一整个雨季
一整个雨季 2021-01-28 07:52

I am using the sqlsrv ms drivers for php, which work fine (tested with normal queries), I have also tested it with running a stored procedure to update table data which also wor

2条回答
  •  灰色年华
    2021-01-28 08:15

    Supposing that the stored procedure is returning the contents of one table with a single SELECT statement, using its output should be as simple as using the result of sqlsrv_query as you would any other selection query result (i.e. using sqlsrv_fetch_object/array on the result)! So the stored proc could look something like this:

    CREATE STORED PROCEDURE test
    AS
        -- do some other stuff here
        -- ...
        SELECT * FROM test
    GO
    

    And in your php:

    // establish db connection, initialize
    // ...
    
    $sql = "{call test}"
    $result = sqlsrv_query($conn, $sql);
    while (sqlsrv_fetch_object($result))
    {
         // do something with the data
         // ...
    }
    

提交回复
热议问题