Pretty print a MARC record retrieved through the PECL yaz extension

  1. <?php
  2. $dir = dirname(__FILE__);
  3. require 'File/MARC.php';
  4.  
  5. // Define the usable fields for our CCL query
  6. $ccl_fields = array(
  7.   "ti" => "1=4",
  8.   "au"  => "1=1",
  9.   "isbn" => "1=7"
  10. );
  11.  
  12. // Declare the array that will hold the parsed results
  13. $ccl_results = array();
  14.  
  15. // Connect to the laurentian.ca Z39.50 server
  16. $conn = yaz_connect('142.51.8.7:2200/UNICORN');
  17. yaz_ccl_conf($conn, $ccl_fields);
  18.  
  19. // Define our query for a most excellent text
  20. $ccl_query = "ti='derby' and au='scott'";
  21.  
  22. // Parse the CCL query into yaz's native format
  23. $result = yaz_ccl_parse($conn, $ccl_query, $ccl_results);
  24. if (!$result) {
  25.   echo "Error: " . $ccl_results['errorstring'];
  26.   exit();
  27. }
  28.  
  29. // Submit the query
  30. $rpn = $ccl_results['rpn'];
  31. yaz_search($conn, 'rpn', $rpn);
  32. yaz_wait();
  33.  
  34. // Any errors trying to retrieve this record?
  35. $error = yaz_error($conn);
  36. if ($error) {
  37.   print "Error: $error\n";
  38.   exit();
  39. }
  40.  
  41. // Retrieve the first MARC record as raw MARC
  42. $rec = yaz_record($conn, 1, "raw");
  43. if (!$rec) {
  44.   print "Error: Retrieved no results.\n";
  45.   exit();
  46. }
  47.  
  48. // Parse the retrieved MARC record
  49. $marc_file = new File_MARC($rec, File_MARC::SOURCE_STRING); 
  50.  
  51. while ($marc_record = $marc_file->next()) {
  52.   print $marc_record;
  53.   print "\n";
  54. }
  55. ?>

Documentation generated on Mon, 01 Jan 2007 23:44:42 -0500 by phpDocumentor 1.3.1