Hi,
I have to do some sql repeatedly. So,I wrote a function. But it's not working with the same statements inside the function. I checked sql stmt, the value of $testval in the function, everything is correct. But when executed it says, Warning: Supplied argument is not a valid OCI8-Connection ,statement resource in c:\ora817\dataentry2.php on line 133.
EX:
WITHOUT FUNCTION: WORKING FINE
if ($value1) {
$sql = "select description from desc_tbl where id_nbr = '$value1'";
$stmt = OCIParse($conn,$sql);
OCIExecute ($stmt);
$nrows = OCIFetch($stmt) or die("Couldn't execute query.");
if ($nrows > 0) {
$desc1 = OCIResult($stmt,1);
}
OCIFreeStatement($stmt);
}
WITH FUNCTION: NOT WORKING (I tried creating sql outside and tried to send sql as an arg. No use.)
function get_desc($testval) {
$sql = "select description desc_tbl where id_nbr = '$testval'";
echo "$testval"; //You could see the value here
$stmt = OCIParse($conn,$sql);
OCIExecute ($stmt);
$nrows = OCIFetch($stmt) or die("Couldn't execute query.");
if ($nrows > 0) {
$desc1 = OCIResult($stmt,1);
return $desc1;
}else{
$desc = '';
}
}
if ($value1) {
$dia_desc1 = get_desc($value1);
}
OCIFreeStatement($stmt);
I checked by substituting direct value in where clause. It is also not working when the sql is inside the function. I tried sending sql as an arg. No use. Sorry for this big posting, but you can understand my problem better.
Any help!!
Thanks
Satya