O
O
Oleg2019-02-06 17:46:13
PHP
Oleg, 2019-02-06 17:46:13

How to get return of MS SQL procedure in PHP 7?

Greetings.
Function returns run perfectly through

$tsql = "SELECT * FROM dbo.GetInfo('.$value.')";
    $stmt = sqlsrv_query($conn, $tsql);
    $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC); // И все получилось. Пришла таблица.

But with the procedure already broke his head.
Can't get response in PHP. Just haven't tried it yet.
$tsql = "exec dbo.GetPrice 'abc'";
$stmt = sqlsrv_prepare($conn, $tsql);
    if ($stmt) {
        echo "Statement prepared.\n";
    } else {
        echo "Error in preparing statement.\n";
        die(print_r(sqlsrv_errors(), true));
    }

    /* Execute the statement. Display any errors that occur. */
    $result = sqlsrv_execute($stmt);
    if ($result) {
        echo "Statement executed.\n";

    } else {
        echo "Error in executing statement.\n";
        die(print_r(sqlsrv_errors(), true));
    }

$stmt In vardump it says "resource(8) of type (SQL Server Statement)".
In this case, the code is executed. SQL accepts and processes the command.
But how to return the result in PHP???
Still here so somewhere advised... having replaced function with procedure. But also zero result.
$tsql = "exec dbo.GetPrice 'abc'";
        $stmt = sqlsrv_query($conn, $tsql);
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);

Even if you explicitly write RETURN in the procedure code. I still can't accept anything.
HELP! ... Where am I stupid?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2019-02-08
@VDT2

ANSWER:
We write at the beginning of the SQL procedure and we get everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question