To SEEK or not to SEEK!

[adrotate group=”3,4,7″]
I have been wrestling with what seemed to be a problem with the i5_data_seek() functions for a few days, the problem I was looking to resolve was how to save the RRN of a record in a list so that I could list only a single field with a link that would display the entire record when requested.

Originally I was using the content of one of the fields to find the record and display is. The following code shows how I looked for the data in the file. I was using a query to look for an array of characters within an array of characters. This was obviously not the best way but I know the strings would all be very different to each other as they represent the confirmation ID returned from an SMTP server.

// copy the string as the id to use
<a href="dspemdets.php?id=<?php echo($rec[2]); ?>">Details</a></td>
function get_email_dets($id,&$conn,$br)
// search through the file for a string in the confirmation field
// LIKE will look for a string within a string
$query = "SELECT * FROM EMLOG where EMCNFM LIKE '" .$id ."%'";
$result = i5_query($query);
// error
if(!$result){
	echo("Error code: " .i5_errno($result));
	echo("Error message: " .i5_errormsg($result));
	return;
	}
// fetch the rows and display
$rec = i5_fetch_row($result);
var_dump($rec)

Initially this all worked fine but I found that when I moved my SMTP server and it returned different confirmation ID’s it stopped working! I think it was something to do with the layout of the characters versus numbers but not sure! The original confirmation ID’s were ‘1276180853 qp 4086’ but the new server returned ‘queued as 4A42913807E’. Not something I understand too much but not working in some instances was not acceptable!

Having used SQL I thought I would use this for retrieving the records passing in the RRN as the record to get, I only did this because my initial tries with using the i5_data_seek() function were getting me nowhere and I needed to fix the problem. After some digging around I found that the DB2 SQL engine has a method of doing this using the RRN token. I could use the i5_bookmark() function to store the RRN as part of the list build and then use that to get the record back when I needed it. Below are the snippets of code which I used.

// use the RRN as the id
<a href="dspemdets.php?id=<?php echo(i5_bookmark($file)); ?>">Details</a></td>
function get_email_dets($id,&$conn,$br) {
// set up the query
// set up the query
$query = "SELECT * FROM EMLOG where RRN(EMLOG) = " .$id;
$result = i5_query($query);
// error
if(!$result){
	echo("Error code: " .i5_errno($result));
	echo("Error message: " .i5_errormsg($result));
	return;
	}
// fetch the rows and display
$rec = i5_fetch_row($result);
var_dump($rec)

This worked fine but I was determined to find out if the i5_data_seek could be used in a similar fashion. I tried to use the manuals as a guide to using this technology and every time it seemed to return an error stating that the parameters passed were wrong. As it turns out the manuals have the wrong information, they show I5_READSEEK as the parameter to be used where it should be I5_READ_SEEK. Some corresponding with Aura Equipment Support put me on the right track and the following code now works! I must admit I was also using I5_DATA_SEEK at one point which caused even more confusion 🙂

$file = i5_open('EMLOG');
if($file === false) {
      die(i5_errormsg());
      return -1;
      }
echo("ID=" .$id);
$result = i5_data_seek($file,$id);
// error
if(!$result){
      echo("Error code: " .i5_errno($result));
      echo("Error message: " .i5_errormsg($result));
      return;
      }
$rec = i5_fetch_row($file,I5_READ_SEEK);
var_dump($rec);

So if you need the save the RRN of a record in a list and use it for retrieval of the full record at a later time then the above shows a number of ways to get the record back.

Chris…

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.