oci_bind_by_name4.htm
Objective: oci_bind_by_name using like clause

Script:

<html>
<head>
<title> oci_bind_by_name4.php</title>
<style type="text/css">
html, body { height: 100%; }
.TB2 { border:2px solid navy; color:green; }
.TB1 { border:2px solid green;color: navy;
vertical-align:text-top;width:300px; height:100px;}
.sp1 { width: 450px; height:100px; overflow:auto;color:navy;}
.td1 { width: 65px; height: 10px;background-color:#b0c4de;}
.td2 { width: 65px; height: 10px; font-size:10px;}
</style>
<body>
<?php
echo "oci_bind_by_name funciton : multiple variables <br/>";
//
$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);
}
$stmt = oci_parse($conn, 'select * from emp where deptno = :dno and job like :ejob');
//BINDING DATA
$earray =array(':dno'=> 30, ':ejob'=> "%SAL%");
foreach($earray as $key =>$val)
{
oci_bind_by_name($stmt, $key, $earray[$key]);
}
oci_execute($stmt);
//
// HEADER TABLE
echo "<table border=\"1\">";
echo "<tr>";

$ncols = oci_num_fields($stmt);
$nrows= oci_num_rows($stmt);
for ($i = 1; $i <= $ncols; $i++) {
$column_name = oci_field_name($stmt, $i);
echo "<td class='td1'>$column_name</td>";
}
//
echo "</tr></table>\n";
//REPORT
echo "<table border='1'>\n";
while(($row=oci_fetch_array($stmt, OCI_ASSOC))){
echo "<tr>\n";
foreach ($row as $item) {
echo "<td class='td2'>".htmlentities($item) . " :&nbsp;"."</td>\n";
} //foreach ends
echo "</tr>\n";
}//while block ends
echo "</table>\n";
//
echo "</tr></table>\n";
oci_free_statement($stmt);
oci_close($conn);
echo "<br/> Oracle db conection closed";
//
?>
</body>
</html>

Display