Hi,
I am fairly new to PHP and I am just trying to tidy up some of my code by using PHP classes. However I must be doing something wrong because when I keep getting this error....
Fatal error: Call to a member function on a non-object in E:\Inetpub\wwwroot\allnorth_test\PHPClass\BusSec2.php on line 126
here is the code that i am using...i am just trying to do a simple select statement and return the results of the query:
<html>
<head>
<title>TESTING2</title>
</head>
<body>
<?
/**********CLASS***************/
class OCI8Hook {
var $ERROR = "";
//----------------------------------------------------------------------
/** PRIVATE
* Returns the SID, USERNAME, and PASSOWORD used to connect to a given
* Oracle database.
*/
function getDBAuth($sid) {
switch (strtoupper($sid)) {
//case "DBXYZ": return (array("usernam1", "secret1", "DBXYZ"));
case "spenney": return (array("spenney", "spenney", "ane"));
}
// I don't know what to do with this host/SID.
return(false);
}
//----------------------------------------------------------------------
/** PRIVATE
* Logs the current message in OCIError to the Apache Log file. This is
* done by first including an application-level error code, and the
* current PHP page identifier.
*/
function dumpError($errcode, $errhndl=0) {
// retrieve the error message...
$error = ($errhndl) ? OCIError($errhndl) : OCIError();
// clean the message...
$this->ERROR = trim($error["message"]);
// log this error to Apache's error log
error_log(sprintf("%s %s %s %s",
$errcode, $_SERVER["PHP_SELF"], $error["code"], $this->ERROR));
}
//----------------------------------------------------------------------
/** PUBLIC (stmt_hndl)
* Returns the statement handle created from the execution of the SQL
* query. If the statement fails, the method returns (false) and the
* error is available in $this->ERROR.
*/
function query($sid, $sql, &$bargs) {
// clear any previous errors.
$this->ERROR = "";
// look up the username, password, and database for this SID
$dbauth = $this->getDBAuth($sid);
if (empty($dbauth) || ! is_array($dbauth)) {
$this->ERROR = "Database Error(1).";
return(false);
}
// connect to the database...
$dbh = @OCILogon($dbauth[0], $dbauth[1], $dbauth[2]);
if (! $dbh) {
$this->dumpError("OCILogon");
return (false);
}
// parse the SQL statement...
$stmt = @OCIParse($dbh, $sql);
if (! $stmt) {
$this->dumpError("OCIParse", $stmt);
return (false);
}
// Bind the args into the statement... (ARG[0], VALUE[1], LEN[2])
foreach ($bargs as $barg) {
$$barg[0] = $barg[1];
@OCIBindByName($stmt, ":$barg[0]", $$barg[0], $barg[2]);
}
// execute sql query
$rslt = @OCIExecute($stmt);
if (! $rslt) {
$this->dumpError("OCIExecute(STMT)", $stmt);
$this->dumpError("OCIExecute(RSLT)", $rslt);
return (false);
}
// if there are bind args, recover them...
$r_bargs = array();
foreach ($bargs as $barg) {
$r_bargs[$barg[0]] = $$barg[0];
}
$bargs = $r_bargs;
// return the sql statement handle upon success
return ($rslt);
}
//----------------------------------------------------------------------
}
//######################################################################
//## END OF CLASS
//######################################################################
$test = new OCI8Hook;
function simple_select_example(){
$sql =sprintf ("SELECT Business_Section_Name FROM Business_section");
//run the query
$stmt = $test->query("spenney", $sql, $bargs);
if(!stmt) return(false);
//loop through the returned rows and convert to a PHP array
$data=array();
while(@OCIFetchInto($stmt, $row, OCI_ASSOC|OCI_RETURN_NULLS))
{
$data[$row["Business_Section_Name"]]=1;}
//return the data that we just fetched...
return($data);
}
echo(simple_select_example());
?>
</body>
</html>
hopefully someone can help me...
thanks
sp