I'm trying to understand OOP and inheritance for the code i'm cleaning up.
I have a config file
Config.php
<?php
$odb_host = "localhost";
$odb_name = "Prod";
$odb_user = "admin";
$odb_pass = "password";
?>
Main.php
class upSellCore{
public function ociConnect($odb_user,$odb_pass,$odb_host,$odb_name)
{
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$odb_host.")(PORT = 1521 )))(CONNECT_DATA=(SID=".$odb_name.")))";
$conn = oci_connect($odb_user, $odb_pass, $db);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
else
{
print "ERR01"; // For PHPUnit assertTrue
}
}
}
$sql = "Select * from users ";
$upSell = new upSellCore();
$upSell->ociConnect($odb_user,$odb_pass,$odb_host,$odb_name);
$stid = oci_parse($upSell,$sql); // Line having issue
Since I've already initialize to call OciConnect but when i try to pass over the object to trigger oci_parse
I'm getting the following error :-
PHP Warning: oci_parse() expects parameter 1 to be resource, object given in /I/main.php on line 46
The $conn
itself is an object from Oracle class but when i overwrite my object $upSell i can't seem to parse the connection into oci_parse.
Taken from PHPManual for end-to-end without using OOP
<?php
$conn = oci_connect('hr', 'welcome', 'localhost/XE', 'AL32UTF8');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$stid = oci_parse($conn, 'SELECT * FROM employees');
oci_execute($stid);
echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
echo "<tr>\n";
foreach ($row as $item) {
echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : " ") . "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
?>