PHP function returning query in oracle database

Asked

Viewed 819 times

0

I’m trying to create a Function in php that brings information from my Oracle database, but Function does not return any value. This Function aims to return some user data.

The function is as follows:

<?php 
function fn_valida_permissao() {
    include ("../../DataBase/conexao.php");

    $chamado_query = "SELECT pu.idusuario IDUSUARIO
                       FROM usuario u
                      WHERE u.idusuario = upper('usuario_de_acesso')";

    $chamado = oci_parse($ora_conexao, $chamado_query);
    oci_execute($chamado);

    while($v_pagina=oci_fetch($chamado)) {
        return $v_pagina = oci_result($chamado, 'IDUSUARIO');
    }
}
?>

Would anyone have any suggestions on how to resolve?

1 answer

1

First, either you didn’t copy it right, or you can see the SQL execution face error. You set FROM only the alias u, but is trying to return pu.idusuario

Second, you don’t need a while if you know that you will only return a record or want to show only one record. Once you run the first return it will go out of function.

while($v_pagina=oci_fetch($chamado)) {

    return $v_pagina = oci_result($chamado, 'IDUSUARIO');

}

Browser other questions tagged

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