lachild Posted January 24, 2008 Share Posted January 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87550-problems-passing-reference/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.