Jump to content

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 webmaster@reliv.com");
}

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 webmaster@reliv.com");
$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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.