oci_define_by_name1
Objective :
  • use of oci_define_by_name to fetch SQL-Columns by name attribute
  • use of oci_fetch() to print/serialize the value of the target column with a while loop.
Script:

<?php
echo "Example OCI_FETCH ..OCI_define_by_name1.php <br/>";
$sql = "select empno, ename from emp WHERE rownum <=6";
$conn = oci_connect('scott', 'Son', 'localhost/orcl.gateway.2wire.net');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
//echo" DB connected: querying a table <br/>";
}
$stmt = oci_parse($conn, $sql);
oci_define_by_name($stmt, 'ENAME', $ename);
oci_define_by_name($stmt, 'EMPNO', $empno);
oci_execute($stmt);
//
while ($row = oci_fetch($stmt)) {
echo $empno. " ".$ename ." <br/>";
}
//
echo " no of rows : ". oci_num_rows($stmt);
oci_free_statement($stmt);
oci_close($conn);
echo "<br/> Oracle db conection closed";
//
?>
 

Display: