pradeep_bansal
asked on
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:...."
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:...."
ASKER
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_GRO UP";
$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\ Monitoring Dashboard\ Copy of testnewConn.php on line 30
Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 31
Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 32
Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 38
<?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"]
var_dump($GLOBALS["conn"])
}
$sql = "select * from ORACLE.PERSON_EMPLOYEE_GRO
$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\
Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
ASKER
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_GRO UP";
$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\ Monitoring Dashboard\ Copy of testnewConn.php on line 30
Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 31
Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 32
Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\ Monitoring Dashboard\ Copy of testnewConn.php on line 38
--------------------------
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_GRO
$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\
Warning: oci_execute() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
Warning: oci_fetch() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
Warning: oci_close() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\xampp\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Cappytoi,
It worked i just missed out this part.
Thanks
It worked i just missed out this part.
Thanks
$db_handler = oci_connect(....);
if (!$db_handler) {
$error = oci_error();
exit ('database connection failed with reason: '.$error);
}