Jump to content

Problems passing reference


lachild

Recommended Posts

Hello everyone I'm having a problem passing a reference to a function.

 

I have tried this a couple of ways.  Both ways still report an error, the code and error messages are below.

 

Here was try one.

$or_login = '';

function or_connect(){
global $or_login;
$or_login = oci_connect('confreg','confreg','dwdb') or die("Internal Error.  Please Contact [email protected]");
}

function or_db_query($query)
{
global $or_login;

$statement = oci_parse ($or_login, $query);

oci_execute ($statement);

while ($row = oci_fetch_array ($statement, OCI_ASSOC)) {
	$return[] = $row;
	}

return $return;
}

 

error:

PHP Warning:  oci_parse() expects parameter 1 to be resource, string given i
PHP Warning:  oci_execute() expects parameter 1 to be resource, string given
PHP Warning:  oci_fetch_array() expects parameter 1 to be resource, string given 

   

Try two sets the reference into a class variable.  I found this solution in the php manual.

 

class Pointer {
     var $i;

     function Pointer() {
          $this->i=null;
          }

     function set(&$_i) {
          $this->i = &$_i;
          }

     function &get() {
          return $this->i;
         }
}

$or_login_global = new Pointer();

function or_connect(){
global $or_login_global;
$or_login_temp=oci_connect('confreg','confreg','dwdb') or die("Internal Error.  Please Contact [email protected]");
$or_login_global->set($or_login_temp);
}

function or_db_query($query)
{
global $or_login_global;
$or_login = &$or_login_global->get();

#$c=OCILogon('confreg','confreg','dwdb');
$statement = oci_parse ($or_login, $query);

oci_execute ($statement);

while ($row = oci_fetch_array ($statement, OCI_ASSOC)) {
	$return[] = $row;
	}
#oci_close($c);	


return $return;
}

 

error:

PHP Warning:  oci_parse() expects parameter 1 to be resource, null given i
PHP Warning:  oci_execute() expects parameter 1 to be resource, null given
PHP Warning:  oci_fetch_array() expects parameter 1 to be resource, null given 

 

Thanks in adavance

Link to comment
https://forums.phpfreaks.com/topic/87550-problems-passing-reference/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.