How to get a Procedure return using ODBC in PHP?

Asked

Viewed 88 times

-1

I am trying to communicate PHP with the Caché database of Intersystems, but I will need to use ODBC to communicate.

My doubt is how I can get PHP to return Procedure, in the case of a String, I’m already able to execute successfully, but the return I do not know how to get. I’m using the functions odbc_prepare and odbc_execute.

My connection to the Database

$usu='usuario';
$senha='senha1234';
$connection_string = 'Driver={InterSystems ODBC35};server=localhost;port=1972;database=MEUBD;protocol=TCP;static cursors=1';
$connection = odbc_connect($connection_string,$usu,$senha);

Execution of my Procedure

<?php
$sqlExecutar = '{CALL %MeuModulo.MinhaClasse_MinhaProcedure(?,?,?)}';
$exc = odbc_prepare($connection, $sqlExecutar);
$par1='Parametro 1';
$par2='Parametro 2';
$par3='Parametro 3';
$result = odbc_execute($exc,array($par1,$par2,$par3));
?>

$result comes back with the value True

How do I get the feedback from Procedure? In case it is returning the word "SUCESSO NA EXECUÇÃO". Is there any method odbc?

Thanks.

1 answer

1


The return is true because it is returning that the function was successfully executed.

Could use the odbc_fetch_array:

$rs = odbc_execute($exc,array($par1,$par2,$par3));

if (is_resource($rs)) {
    while ($result[] = odbc_fetch_array($rs)) {
    }
    odbc_free_result($rs);
    $this->close();
    return $result;
} else {
    $this->halt('Database query error', $sql);
}

Sources: Link 1, Link 2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.