문제

I need to execute a mssql stored procedure for each element in my array, how do I do this... I have an example here, but it's only executing ONCE. Im guessing the DB is locked while executing the first time and that's why it's only executing once.

Should I make a recursive function? and only run the procedure if the output it TRUE??

here is my code:

    function executeStoreProcedure($movementsArray = array(), $mssql_link) {

    $output;
    $retval;

    $spName = "SDNuevaOperacion";

    var_dump($movementsArray);

    foreach($movementsArray as $movement) {

        $statement = mssql_init("SDNuevaOperacion", $mssql_link);

        $isBinded = mssql_bind($statement, "@PRSLink", $movement["client_id"], SQLINT1);
        $isBinded = mssql_bind($statement, "@UserLogged", $movement["imei"], SQLVARCHAR, false, false, 30);
        $isBinded = mssql_bind($statement, "@AutoInc", $movement["move_id"], SQLINT1);
        $isBinded = mssql_bind($statement, "@Fecha", $movement["move_date"], SQLVARCHAR);
        $isBinded = mssql_bind($statement, "@CantBotEntr", $movement["delivery"], SQLINT1); 
        $isBinded = mssql_bind($statement, "@CantBotRet", $movement["withdrawal"], SQLINT1);
        $isBinded = mssql_bind($statement, "@Pago", $movement["payment"], SQLFLT8); 
        $isBinded = mssql_bind($statement, "@Resultado", $output, SQLVARCHAR, true, false, 2);  

        $retval = mssql_execute($statement);

        $result = $output;

        mssql_free_statement($statement);

        var_dump($retval);
        var_dump($result);

        return $result;

    }

}
도움이 되었습니까?

해결책

Try the same with the return outside of the loop ;)

The first time it is reached, the function exits, so nothing else is done.

You can use exceptions mechanism if you want to stop execution if an error occurs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top