<!DOCTYPE html>
<html>
<!-- try-insert.php - demo need for oci_commit when making
changes to an Oracle database using OCI8
adapted from examples from Peter Johnson
adapted by: Sharon Tuttle
last modified: 4-24-13
-->
<title> Demo Need for oci_commit when making changes to
an Oracle database using OCI8
</title>
<meta charset="utf-8" />
</head>
<body>
<h1> Demo Need for oci_commit when making changes to an Oracle
Database using OCI8 </h1>
<?php
// do you need to ask for username and password?
if (! array_key_exists('username', $_POST))
{
print <<<PASSWORD_FORM
<form method="post" action="$_SERVER[PHP_SELF]">
<label> Username:
<input type="text" name="username" /> </label>
<br />
<label> Password:
<input type="password" name="password" />
</label> <br />
<input type="submit" value="Log in" />
</form>
PASSWORD_FORM;
}
else // you HAVE the username and password
{
$username = htmlspecialchars($_POST['username']);
// do we really need to strip/sanitize this...?
$password = $_POST['password'];
// try to connect to Oracle student database on cedar
$db = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = cedar.humboldt.edu)
(PORT = 1521))
(CONNECT_DATA = (SID = STUDENT)))";
// now try to log on to this database
$conn = oci_connect($username, $password, $db);
if ($conn == false)
{
echo "<p> Oops, could not log into Oracle server </p>";
require("my-std-footer.html");
exit;
}
// setting up an Oracle insert statement, and then executing it
// (notice the bind variable, roughly analogous to the ?
// in a Java PreparedStatement)
$insert = 'insert into log_table '.
'values '.
'(:bind1, sysdate)';
$ins_stmt = oci_parse($conn, $insert);
// here's how you set the bind variable
oci_bind_by_name($ins_stmt, ":bind1", $username, 15);
$num_inserted = oci_execute($ins_stmt, OCI_DEFAULT);
print "<h3>inserted: ".$num_inserted." rows?</h3>\n";
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// commit the change! MAY need this to SEE the change!
// (comment this out to check...)
oci_commit($conn);
// close statement and connection...
oci_free_statement($ins_stmt);
oci_close($conn);
}
require("my-std-footer.html");
?>