PHP and Oracle Connection

I have a xampplite software.
I am trying to connect PHP webpage with Oracle database which resides on the remote location.
I have Oracle 10.2.0 installed on my machine and connection string for that remote database is there in the tnsnames.ora.
I tried with myself but getting errors as mentioned below:-
"Warning: oci_parse() expects parameter 1 to be resource, null given in C:......"
"Warning: oci_execute() expects parameter 1 to be resource, null given in C:...."
"Warning: oci_fetch() expects parameter 1 to be resource, null given in C:...."
pradeep_bansalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cappytoiCommented:
Are you sure the connection established? You can check the resource returned from oci_connect with:

$db_handler = oci_connect(....);
if (!$db_handler) {
 $error = oci_error();
 exit ('database connection failed with reason: '.$error);
}
pradeep_bansalAuthor Commented:
Below is the code i have written for this purpose. I have mentioned the results also i am getting on the webpage

<?php
if ($c = oci_connect(......)) {
   echo "Successfully connected to Oracle.";
   oci_close($c);
 } else {
   $err = oci_error();
   echo "Oracle Connect Error " . $err['text'];
 }
function global_keyword()
{
    global $conn;
    var_dump($conn);
    oci_close($conn);  // this seems to do nothing
    var_dump($conn);
}
function global_array()
{
    var_dump($GLOBALS["conn"]);
    oci_close($GLOBALS["conn"]);  // this works
    var_dump($GLOBALS["conn"]);
}
$sql = "select * from ORACLE.PERSON_EMPLOYEE_GROUP";
   $s = oci_parse($c, $sql);
   oci_execute($s, OCI_DEFAULT);
   while (oci_fetch($s)) {
   echo "COL1 = " . oci_result($s, "COL1") .
   ", COL2 = " . oci_result($s, "COL2") . "<br>\n";
}
oci_close($c);
?>

Results:-

Successfully connected to Oracle.
Warning: oci_parse() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 30

Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 31

Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 32

Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 38
pradeep_bansalAuthor Commented:
Please ignore above comment
-------------------------------------
Below is the code i have written for this purpose. I have mentioned the results also i am getting on the webpage
------------------------------------------------------------------
<?php
if ($c = oci_connect(......)) {
   echo "Successfully connected to Oracle.";
   oci_close($c);
 } else {
   $err = oci_error();
   echo "Oracle Connect Error " . $err['text'];
 }
$sql = "select * from ORACLE.PERSON_EMPLOYEE_GROUP";
   $s = oci_parse($c, $sql);
   oci_execute($s, OCI_DEFAULT);
   while (oci_fetch($s)) {
   echo "COL1 = " . oci_result($s, "COL1") .
   ", COL2 = " . oci_result($s, "COL2") . "<br>\n";
}
oci_close($c);
?>
-----------------------------------------------------------------
Results:-
-----------------------------------------------------------------
Successfully connected to Oracle.
Warning: oci_parse() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 30

Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 31

Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 32

Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\MonitoringDashboard\Copy of testnewConn.php on line 38
cappytoiCommented:
if ($c = oci_connect(......)) {
   echo "Successfully connected to Oracle.";
   oci_close($c);

you closed oracle connection there? that will set $c to null ofc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pradeep_bansalAuthor Commented:
Hi Cappytoi,

It worked i just missed out this part.

Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.