session_id = session_id();
if ($_REQUEST['cmd'] != 'getemp') {
$html=<<
First Name:
Last Name:
BLAB;
$r = $session->Read();
print_r($r);
$fn = $r['first_name'];
$ln = $r['last_name'];
printf($html, $fn, $ln);
} else {
# include_once "functions.php";
include_once "hr/DB/Employee.php";
$employee = new Employee();
$r = $_REQUEST;
$session->Store($r);
$employee->first_name = $r['first_name'];
$employee->last_name = $r['last_name'];
print_r($r);
$employee->read();
print "
";
print $employee->dump();
}
$session->commit();
?>
// hr/DB.php
db = oci_connect('hr', 'hr', 'orcl');
}
function commit() {
oci_commit($this->db);
}
function rollback() {
oci_rollback($this->db);
}
function print_table($table) {
print "\n";
foreach ($table as $row) {
print "";
foreach ($row as $cell) {
if (!isset($cell)) {$cell = 'n/a'; }
print " $cell | ";
}
print "
\n";
}
print "
\n";
}
}
?>
dbconnect();
$sql3 =
'select first_name, last_name, salary from employees where
last_name = :last_name and
first_name = :first_name';
$q = oci_parse($this->db, $sql3);
oci_bind_by_name($q, ":last_name", $_REQUEST['last_name'],-1,
SQLT_CHR );
oci_bind_by_name($q, ":first_name", $_REQUEST['first_name'],-1,
SQLT_CHR );
$r = oci_execute($q, OCI_DEFAULT);
$table = oci_fetch_array($q, OCI_ASSOC+OCI_RETURN_NULLS);
$this->salary = $table['SALARY'];
$this->first_name = $table['FIRST_NAME'];
$this->last_name = $table['LAST_NAME'];
}
function dump() {
$d = sprintf ("First Name: %s
\n
Last Name: %s
\n
Salary : %s
\n",
$this->first_name,
$this->last_name,
$this->salary);
return $d;
}
}
request\n";
print_r($_REQUEST);
if ($_REQUEST['cmd'] != 'getemp') {
$html=<<
First Name:
Last Name:
BLAB;
print $html;
} else {
include_once "functions.php";
include_once "hr/DB/Employee.php";
$employee = new Employee();
$employee->first_name = $first_name;
$employee->last_name = $last_name;
$employee->read();
print "
";
print $employee->dump();
}
?>
dbconnect();
}
function Store($data) {
$data = serialize($data);
$sql =
'merge into session_data
using (select 1 from dual)
on (session_id = :session_id)
when matched then update
set data = :data, change_date=sysdate
when not matched then
insert (
id,
session_id,
data,
change_date
) values (
hr_seq.nextval,
:session_id,
:data,
sysdate)';
$q = oci_parse($this->db, $sql);
oci_bind_by_name($q, ":session_id", $this->session_id,-1,
SQLT_CHR );
oci_bind_by_name($q, ":data", $data,-1,
SQLT_CHR );
$r = oci_execute($q, OCI_DEFAULT);
return 0;
}
function Read() {
$sql =
'select data from session_data where
session_id = :session_id';
$q = oci_parse($this->db, $sql);
oci_bind_by_name($q, ":session_id", $this->session_id,-1,
SQLT_CHR );
$r = oci_execute($q, OCI_DEFAULT);
$table = oci_fetch_array($q, OCI_ASSOC+OCI_RETURN_NULLS);
$d = $table['DATA'];
$this->data = unserialize($d);
return $this->data;
}
}