Irnias
Irnias

Reputation: 21

execute stored procedure using sqlsrv in php 7+

I'm using a PHP 7+ and connecting with SQL-Server using sqlsrv method.

While using normal queries its working fine but the thing is that I need to run a stored procedure and its not working.

This is the test that I've made but I assume if I could get this work I will be able to reproduce the solution in all procedures.

SQL side:

    CREATE PROCEDURE dbo.load_Info_proc 
    AS
    SELECt * from Load_Info
    RETURN 0

PHP side:

    <?php 

    include ( 'conection.php');


    $sql = "{CALL load_Info_proc}";
    $stmt = sqlsrv_prepare($conn, $sql);
    if (!sqlsrv_execute($stmt)) {
    echo "Your code is fail!";
    echo sqlsrv_errors($sql);
    die;
    }
    while($row = sqlsrv_fetch_array($stmt)){
    var_dump($row);
    }

    ?>

I'm missing something?

I expect to see que table rows and in others case just get the query run.

Upvotes: 1

Views: 1916

Answers (1)

Irnias
Irnias

Reputation: 21

die( print_r( sqlsrv_errors(), true));

I just update the error message and it indicate the solution:

It was a permission issue. The username that i was using to connect into the database was not able to execute stored procedures.

Upvotes: 1

Related Questions