Return value from Oracle function

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
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:
<?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:
<?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;
 }
 ?>
 
Ok I solved it.
The problem was I didnt put length to the return value
It shold have been like that:
Code:
oci_bind_by_name($stid, ':compid_desc_bv', $compid_desc,30);
 
Back
Top