Tech Blog

item.php

  • Author: Ken Herold
  • Additional author(s):
  • Institution:
  • Year: 2008
  • License: BSD style
  • Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.
  • Link to terms: Detailed license terms

Description

Script prompts for single item_barcode (GET) and returns results of sql query.

State

Stable

Download

See sample code below for core PHP.

Working example

http://lib.hamilton.edu:3000/item.php?barcode=1000228769

Installation instructions

Using PHP 5.2.0 oci8 calls into Oracle 9.2.0 on Apache 2.0.59 for Voyager 6.5.3. Secure local credentials in ../db-include.inc

<Code sample>
<?
$entry = $_GET['barcode'];
if (is_null($entry))  {
?>
 
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="GET">
Enter Item Barcode Number:
<input type="text" name="barcode" /> <br />
<input type="submit" name="Get details" />
</form>
<?
   } else {
 
// This include file contains the logon username, password, and database name
require('../db-include.inc');
 
// Connect to the database by passing logon information
$iDBConn = OCIpLogon(DB_USER, DB_PASS, DB_NAME);
 
// Define your query in SQL
$query = "
    SELECT DISTINCT
        item_barcode.item_barcode, mfhd_master.display_call_no, mfhd_item.item_enum,
        item.historical_charges, item.historical_browses, item.recalls_placed,
        item.holds_placed, item_type.item_type_name,
        bib_text.bib_id, bib_text.title,
        item_status_type.item_status_desc
    FROM item_barcode, item, item_type, bib_item, bib_text,
        item_status, item_status_type, mfhd_item, mfhd_master
        WHERE
        item.item_id = item_barcode.item_id and
        item.item_type_id = item_type.item_type_id and
        item.item_id = bib_item.item_id and
        bib_item.bib_id = bib_text.bib_id and
        item.item_id = item_status.item_id and
        item.item_id = mfhd_item.item_id and
        mfhd_master.mfhd_id = mfhd_item.mfhd_id and
        item_status.item_status = item_status_type.item_status_type and
        item_barcode.item_barcode = '$entry' " ;
 
// Get a statement identifier from the database using OCIParse
$iStatement = @OCIParse($iDBConn, $query);
 
// Verify that the SQL statement is valid
$arrError = OCIError($iStatement);
if ($arrError['code']) {
    print $arrError['message'];
    OCIRollback($iDBConn);
    exit;
}
 
// Run the query on the database
@OCIExecute($iStatement, OCI_DEFAULT);
 
// Display the select statement
//  echo "Select statement = $query<br><br>";
 
echo "<table width=100%><tr><td><ul>";
echo "<li>BARCODE";
echo "<li>CALL NUMBER";
echo "<li>ENUM";
echo "<li>HISTORICAL CHARGES";
echo "<li>HISTORICAL BROWSES";
echo "<li>CURRENT RECALLS";
echo "<li>CURRENT HOLDS";
echo "<li>ITEM TYPE";
echo "<li>BIB ID";
echo "<li>TITLE";
echo "<li>ITEM STATUS";
echo "</ul><td>";
$cols = OCINumCols($iStatement);
while (OCIFetch($iStatement)) {
   for ($i = 1; $i <= $cols; $i++) {
      print OCIResult($iStatement,$i);
      print "<br>";
   }
}
// end of else statement
}
echo "</td></tr></table>";
?>
<hr>
<?
printf(date('F j Y'));
// OCILogoff($iDBConn);
?>
</Code sample>

TO DO list

Should be portable to oci10 calls into Oracle 10g on Voyager 7

Known issues

Multiple item statuses display with repeated full record.

Leave a Reply