Iterators

chinmay.sahoo

New member
There is another way to navigate through a result set, and that is with an iterator. Using an iterator to iterate over the result set does not involve calling any functions, so it is therefore a bit faster than when you would use one of the fetch functions. In this example, we present the search.php script to find an email matching certain words:

<?php
$db = new SQLiteDatabase("./crm.db", 0666, &$error)
or die("Failed: $error");
if ($argc < 2) {
echo "Usage:\n\tphp search.php <search words>\n\n";
return;
}
function escape_word(&$value)
{
$value = sqlite_escape_string($value);
}
$search_words = array_splice($argv, 1);
array_walk($search_words, 'escape_word');
$words = implode("', '", $search_words);;

The parameters that are passed to the script are the search words, which we, of course, need to escape with the sqlite_escape_string() function. In the previous example, we use the array_walk() function to iterate over the array and escape the words. After they are escaped, we construct a list of them to use in the queries with the implode() function.
 
Back
Top