User's Manual
Using Oracle LOBs to Store and Load Employee Images
Beta Draft Loading Images 7-5
if (!$r) {
$e = db_error($stid, __FILE__, __LINE__);
return false;
}
if (!$lob->savefile($imgfile)) {
$e = db_error($stid, __FILE__, __LINE__);
return false;
}
$lob->free();
return true;
}
To tie the new EMPLOYEE_PHOTOS and EMPLOYEES tables together we need to
use the same employee id in both.
12. Edit anyco_db.inc. Change the $bindvars parameter in
db_execute_statement() to &$bindvars so that OUT bind variable values
are returned from the database. At the bottom of the function add a loop to set any
return bind values:
function db_execute_statement($conn, $statement, &$e, &$bindvars = array())
{
...
$r = @oci_execute($stid);
if (!$r) {
$e = db_error($stid, __FILE__, __LINE__);
return false;
}
$outbinds = array();
foreach ($bindvars as $b) {
$outbinds[$b[0]] = $$b[0];
}
$bindvars = $outbinds;
return true;
}
13. Edit anyco.php. Change the INSERT statement in insert_new_emp() so that it
returns the new employee identifier in the bind variable :neweid. This value is
inserted with the image into the new EMPLOYEE_PHOTOS table.
$statement =
'INSERT INTO employees
(employee_id, first_name, last_name, email, hire_date,
job_id, salary, commission_pct, department_id)
VALUES (employees_seq.nextval, :fnm, :lnm, :eml, :hdt,
:jid, :sal, :cpt, :did)
RETURNING employee_id into :neweid’;
Also in insert_new_emp(), add an array_push() to set a new bind variable
NEWEID at the end of the list of array_push() calls:
array_push($bindargs, array('CPT', $newemp['commpct'], -1));
array_push($bindargs, array('DID', $newemp['deptid'], -1));
array_push($bindargs, array('NEWEID', null, 10));
Because the value of NEWID is being retrieved with the RETURNING clause in the
INSERT statement, its initial value is set to NULL . The length is set to 10 to allow
enough digits in the return value.