FYI_OCI8_PHP functions:
There are numerous PHP functions are available pertained to  web-reporting or querying oracle db over the internet . Few key categories are mentioned below.
  • Connect or  Persistent connect: Persistent connections are cached and reused between requests.
  • Parse:  weight local preparatory steps before query  execution.
  • Bind: An optional step that allows the bindings of placeholder name to the variables/data values.
  • Execute : Step that processes the statement and buffer any results. (** See notes below)
  • Fetch: Gets query results from the database
    • fetch_all: gets all results at once
    • fetch_array(): gets the next row as an array (indexed with integers or BOTH)
    • fetch_assoc(): gets the next row an associative array (indexed with strings), example :
      foreach($row as $item) { $item will print value of each row }
    • fetch_object(): fetch next row as an object
    • fetch_row(): gets the next row of an indexed array
  • Field: retrieves field informatio n
  • Commit: committing a transaction
  • error (oci_error())
    • $e["code']: Oracle error number
    • $e["message"]: Oracle error message
    • $e{"offset"]: detect column  position
    • $e["sqltext"]: detect text of the sql statement
An example:


// connecting to db/Scott's account

$conn = oci_connect('scott', 'pwd', 'localhost/');

//parsing and executing a statement
$stmt = oci_parse($conn, $sql);
//printing data in table format.

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";

//freeing result set and closing db


The htmlentities() function prevents any user data or operations like  '<' to be interpreted as an HTML tag. In many cases you will want to use this function's optional ENT_QUOTES parameter. You should also use the optional character set parameter, specifying a value that matches the character set of your document.

Demo oputput

  • OCI8’s default commit behavior is like other PHP extensions but different from Oracle Database’s standard. The default mode of oci_execute() is OCI_COMMIT_ON_SUCCESS to
    commit changes.
  • Script: auto-commit with php
    $stmt = oci_parse($conn, "insert intoTable1 values (7689,'SMITH')");
    oci_execute($stmt); // automatically committed by default
  • Explicit No_autocommit
    $stmt = oci_parse($conn, "insert into Table1 values (7689,'SMITH')"); -
    oci_execute($stmt, OCI_NO_AUTO_COMMIT); // not committed (in practice it did commit)
  • In CREATE  and DROP  operations database assumes auto commit,
  • With PDO: you may use $dbh->commit();