fdanish Posted May 9, 2010 Share Posted May 9, 2010 Dear friends, I'm a newbie in OOP. Been given a task to convert PHP-MySQL to PHP-Oracle. DB conversion completed successfully. I'm currently stuck at PHP coding. Appreciate if you could advise on what's wrong in my code as below. I'm using a newly constructed class to interact with Oracle as below : <?php //File: dbConn.php class dbConn { private $user; private $pswd; private $db; public $conn; private $query; private $row; private $exec_mode; public function __construct($user, $pswd, $db, $exec_mode= OCI_COMMIT_ON_SUCCESS) { $this->user = $user; $this->pswd = $pswd; $this->db = $db; $this->exec_mode = $exec_mode; $this->GetConn(); } private function GetConn() { if(!$this->conn = oci_pconnect($this->user, $this->pswd, $this->db)) { $err = oci_error(); trigger_error('Failed to establish a connection: ' . $err['message']); } } public function query($sql) { if(!$this->query = oci_parse($this->conn, $sql)) { $err = oci_error($this->conn); trigger_error('Failed to execute SQL query: ' . $err['message']); return false; } else if(!oci_execute($this->query, $this->exec_mode)) { $err = oci_error($this->query); trigger_error('Failed to execute SQL query: ' . $err['message']); return false; } return true; } public function fetch() { if($this->row=oci_fetch_assoc($this->query)){ return $this->row; } else { return false; } } } ?> In a PHP script (getUser.php), I need to call for a class which is in another script (clsRobe.php). From this clsRobe.php, an attempt to use a function in dbConn.php produced an error "Fatal error: Call to a member function query() on a non-object in '\classes\clsRobe.php'". Extraction of getUser.php : <?php //File getUser.php require_once ('../include/dbConn.php'); require_once('classes/clsRobe.php'); $db = new dbConn($user, $pswd, $conn); $stfQry=$db->query("select robe_type from staff where id='" . $stfID . "'",OCI_ASSOC + OCI_RETURN_NULLS); $stfAry=$db->fetch(); $robQry=$db->query("select robe_status from robe where robe_type='" . $stfAry['ROBE_TYPE'] . "'"); $robRow=$db->fetch(); $robe = new clsRobe; // calling a class from clsRobe.php $robeAvail = $robe->getAvailableRobeSize($stfAry['ROBE_TYPE']); . . ?> Extraction of clsRobe.php : <?php class clsRobe{ function getAvailableRobeSize($robeType){ $sqlRobe="select robe_size_s, robe_size_m, robe_size_l, robe_size_xl, robe_size_xxl from robe where robe_type='" . $robeType . "'"; $qryRobe=$db->query($sqlRobe); // error $rstRobe=$db->fetch($qryRobe); // error . . ?> Please advise. Thanks. Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/ Share on other sites More sharing options...
andrewgauger Posted May 10, 2010 Share Posted May 10, 2010 switch these lines: require_once('classes/clsRobe.php'); $db = new dbConn($user, $pswd, $conn); as: $db = new dbConn($user, $pswd, $conn); require_once('classes/clsRobe.php'); Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/#findComment-1056145 Share on other sites More sharing options...
fdanish Posted May 11, 2010 Author Share Posted May 11, 2010 Thanks andrew, I've tried that, but still getting same error. It seems that class clsRobe unable to get value from class dbConn via getUser.php. Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/#findComment-1056192 Share on other sites More sharing options...
ignace Posted May 11, 2010 Share Posted May 11, 2010 andrew you are getting sloppy change function getAvailableRobeSize($robeType) to function getAvailableRobeSize($robeType, $db) call it like: $robeAvail = $robe->getAvailableRobeSize($stfAry['ROBE_TYPE'], $db); Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/#findComment-1056313 Share on other sites More sharing options...
andrewgauger Posted May 11, 2010 Share Posted May 11, 2010 Scope of an (un)global. duh..... Guess I am getting sloppy. Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/#findComment-1056504 Share on other sites More sharing options...
fdanish Posted May 12, 2010 Author Share Posted May 12, 2010 andrew you are getting sloppy change function getAvailableRobeSize($robeType) to function getAvailableRobeSize($robeType, $db) call it like: $robeAvail = $robe->getAvailableRobeSize($stfAry['ROBE_TYPE'], $db); ignace, Yezzzaaa...... it works! Thank you sooo much. Link to comment https://forums.phpfreaks.com/topic/201151-php-mysql-oracle-oop-error/#findComment-1056867 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.