PHP ORACLE VIEW FROM SELECT

Asked

Viewed 697 times

0

I intend to generate a view through a select with the code below, but it doesn’t work, which may be?

$row[0] contains "select col1, col2, col3, col4, col5 from tabela1"

$select= oci_parse($ora_conexao, 'SELECT * FROM TABELA');
oci_execute($select);
while (($qrow = oci_fetch_row($select)) != false) {
    $arrData[] = $row[0].'<br />';
}
$var = implode('',$arrData);
//--> cria temp view
$view = oci_parse($ora_conexao,"CREATE OR REPLACE FORCE VIEW \"TD_ADMIN\".\"view1\" (\"col1\", \"col2\", \"col3\", \"col4\",  \"col5\") AS $var");
oci_execute($view);
  • Your description. Any error message appears?

  • no, the page is blank.

  • 1

    Put that at the top of the page, ini_set('display_error', true); error_reporting(E_ALL); see if the error appears.

  • continues blank, by the way, now I have given an echo on the connection to the bank and it presents OK for the connection and the select of the variable $var gives the result 'select col1... from Tabela1'...

  • So it’s all right, only one left to do fetch() get the results, in the database the view is created?

  • to test the creation of the view, I replaced the value of the $var variable with the result of $select and generated the view, so the problem must be in that chunk of the $view variable... :/ fetch() fits where?

  • 1

    found the error... :/ on the line $arrData[] = $Row[0]. '<br />'; the line break for the select in the creation of the view gives sql error but did not show on the screen... : $arrData[] = $Row[0]; now yes, all solved. Thanks for the help rray.

  • Creates an answer with these details :) Aaah yes syntax error.

Show 3 more comments

1 answer

1

discovered the error by removing the line break here: $arrData[] = $Row[0].'
';

was like that and working:

connection to the bank:

//--> conexao oracle
//--> usuario
$ora_user = "ora_user"; 
//--> senha
$ora_senha = "ora_senha"; 
//--> caminho
$ora_bd = "(DESCRIPTION=
          (ADDRESS_LIST=
            (ADDRESS=(PROTOCOL=TCP) 
              (HOST=192.168.1.100)(PORT=1521)
            )
          )
          (CONNECT_DATA=(SERVICE_NAME=SERVICE_TESTE))
     )"; 
//--> monta a conexao
if ($ora_conexao = oci_connect($ora_user,$ora_senha, $ora_bd, 'AL32UTF8')){
    echo 'Conexão bem sucedida';
}else{
    echo 'Conexão falhada';
}

creates oracle database select view:

$select= oci_parse($ora_conexao, 'SELECT * FROM TABELA');
oci_execute($select);
while (($qrow = oci_fetch_row($select)) != false) {
    $arrData[] = $row[0];
}
$var = implode('',$arrData);
//--> cria temp view
$view = oci_parse($ora_conexao,"CREATE OR REPLACE FORCE VIEW \"TD_ADMIN\".\"view1\" (\"col1\", \"col2\", \"col3\", \"col4\",  \"col5\") AS $var");
oci_execute($view);

Browser other questions tagged

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