Return value from Oracle function

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: egami, macek, gesf

Post Reply
ohad
New php-forum User
New php-forum User
Posts: 8
Joined: Fri May 22, 2020 9:08 am

Fri Jun 05, 2020 11:38 pm

Hi
I try to get data from a fuction in my Oracle DB
I use this syntax but the reply is null value
I know the function works cause i use it in other developing tool
I know the connection i declared is working, cause i get values when i do dirext select from the PHP
Cam you see what is the problem?

index.php

Code: Select all

<?php
    require_once("../xxx/Includes/GlDbOra.php");
    
if (isset($_POST['compid_typed']))
    {
    $compid=$_POST['compid'];
  $compname = (DBOracle::getInstance()->get_company_name($compid));
    }
 ?>   
/xxx/Includes/GlDbOra.php

Code: Select all

<?php

class DBOracle {
    private static $instance = null;
    private $OracleUser="xxx";
    private $OraclePwd="xxx";
    private $OracleDB="xxx";

    public static function getInstance() {
   if (!self::$instance instanceof self) {
     self::$instance = new self;
   }
   return self::$instance;
 }
      public function __clone() {
        trigger_error('Clone is not allowed.', E_USER_ERROR);
    }
    
    public function __wakeup() {
        trigger_error('Deserializing is not allowed.', E_USER_ERROR);
    }
    
    public function __construct () {
 
    $this->con = oci_connect($this->OracleUser, $this->OraclePwd, $this->OracleDB);
    if (!$this->con) {
        $m = oci_error();
        echo $m['message'], "\n";
        exit;
    }
}
public function get_company_name($compid) 
{
    $query = "begin :compid_desc_bv := get_compid_desc(incompid => :compid_bv); end;";
    $stid = oci_parse($this->con, $query);
    oci_bind_by_name($stid, ':compid_bv', $compid);
    oci_bind_by_name($stid, ':compid_desc_bv', $compid_desc);
    oci_execute($stid);
    echo $compid_desc;
    oci_free_statement($stid);
    oci_close($this->con);
    return $compid_desc;
 }
 ?>
ohad
New php-forum User
New php-forum User
Posts: 8
Joined: Fri May 22, 2020 9:08 am

Sat Jun 06, 2020 8:05 am

Ok I solved it.
The problem was I didnt put length to the return value
It shold have been like that:

Code: Select all

oci_bind_by_name($stid, ':compid_desc_bv', $compid_desc,30);
Post Reply