Page 1 of 1

oci_bind_by_name doesnot update the php array value

Posted: Thu Dec 23, 2010 10:45 am
by novice4eva
Hi there friends, I had a strange problem and I think I am missing something and you might have an elegant solution. This example is in CI(codeigniter) but I faced similar problem when plain oci library was used too. What I wanted was the value of the index 'value' of the array to be filled with the values returned by oracle procedure.

Code: Select all

$args = array(
                    array('name'=>'request_id','value'=>5,'length'=>10,'type'=>OCI_B_INT)
                    ,array('name'=>'vessel_length_overall','value'=>NULL,'length'=>10,'type'=>OCI_B_INT)//OUT PARAMS
                    ,array('name'=>'total_engine_hp','value'=>NULL,'length'=>10,'type'=>OCI_B_INT)//OUT PARAMS
                    .....................................................
                  );
       $return = $this->db->stored_procedure('PKG_REQUEST','PR_GET_SUITE_BASELINE',$args);
and this stored_procedure function calls "_bind_params" function below
and the function that binds parameter is like this:

Code: Select all

/* EXACT COPY FROM CODE IGNITER*/
 function _bind_params($params) {
        if (!is_array($params) OR !is_resource($this->stmt_id)) {
            return;
        }

        foreach ($params as $param) {
           
            foreach (array('name', 'value', 'type', 'length') as $val) {
                if (!isset($param[$val])) {
                    $param[$val] = '';
                }
            }

            ocibindbyname($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
        }
    }
And I had to modify this code to this:

Code: Select all

/* RETURN ARRAY HOLDS THE OUT PARAMETER VALUES*/
 function _bind_params($params,&$return=array()) {
        if (!is_array($params) OR !is_resource($this->stmt_id)) {
            return;
        }

        foreach ($params as $param) {
            $return[$param['name']]=$param['value'];
            foreach (array('name', 'value', 'type', 'length') as $val) {
                if (!isset($param[$val])) {
                    $param[$val] = '';
                }
            }

            ocibindbyname($this->stmt_id, $param['name'], $return[$param['name']], $param['length'], $param['type']);
        }
    }
basically what I am doing is creating another array (single dimension) and it solves my issue.

These are what I've already tried :
So I've tried passing the $args,$param array by reference(although I think now php5 does it by defult!! don't know), and I checked out some other forums and what they had was something like this (of course didn't work):

Code: Select all

$args = array(
                    array('name'=>'request_id','value'=>retValue($params, 'request_id'),'length'=>10,'type'=>OCI_B_INT)
                    ,array('name'=>'vessel_length_overall','value'=>&$val1,'length'=>10,'type'=>OCI_B_INT)
.............
Eagerly waiting for your opinion folks :D