OCIbindName_StoredFunc1.htm
Oci_bind_by_name function tenders the memory address of the data to oracle engine, through a variable which must contain valid in bound data. It appears to be safer and reduces security risks.
Stored Function :

PHP Scripts : compared with oci_bind_name with regular
  • Using I : oci_bind_name for stored Procdure
    <?php
    $sql = "";
    if(isset($_POST['submit']))
    {
    $sql = $_POST['sql'];
    echo "Oracle sql-query <span class='sp1'> <br/>:" . $sql ."</span>";
    $conn = oci_connect('hr', '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_bind_by_name($stmt, ":bv", $p1, 6);
    $result= oci_execute($stmt);
    echo"<br/> Output ..".$p1. ".. end of message<br/>";
    oci_free_statement($stmt);
    oci_close($conn);
    echo "<br/> Oracle db connection closed";
    //
    }
    ?>
  • Using II : PHP script supporting Select and Dual table:
    <?php
    $sql = "";
    if(isset($_POST['submit']))
    {
    $sql = $_POST['sql'];
    echo "Oracle sql-query <span class='sp1'> <br/>:" . $sql ."</span>";

    $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" Error in connection <br/>";
    }
    $stmt = oci_parse($conn, $sql);
    oci_execute($stmt);

    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";
    //
    echo "<table border='1'>\n";
    while($row = oci_fetch_array($stmt, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
    echo "<td class='td2'>".($item !== null ? htmlentities($item, ENT_QUOTES):"&nbsp;")."</td>\n";
    } //foreach ends
    echo "</tr>\n";
    }//while block ends
    echo "</table>\n";
    //
    echo " no of rows : ". oci_num_rows($stmt);
    oci_free_statement($stmt);
    oci_close($conn);
    echo "<br/> Oracle db conection closed";
    //
    }
    ?>
 

Query Stored Function using : oci_bind_by_name($stmt, ":bv", $p1, 6)
begin:bv:=CTOF(29.25);END;

Stored Function :

select CTOF(25.21) as CElFah from dual