Prev | Current Page 64 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"


$qi= new QueryIterator("golpo","postgres2","");
$qi->exceute("select name, email from users");
while ($qi->valid())
{
Chapter 3
[ 55 ]
print_r($qi->current());
$qi->next();
}
?>
For example, if there are two records in our table users, you will get the following
output:
Array
(
[name] => Afif
[email] => mayflower@phpxperts.net
)
Array
(
[name] => Ayesha
[email] => florence@phpxperts.net
)
Quite handy, don't you think?
ArrayObject
Another useful object introduced in PHP5 is ArrayObject that wraps the regular
PHP array and gives it an OO flavor. You can programmatically access the array
in an OO style. You can create an ArrayObject object by simply passing to
ArrayObject constructor. ArrayObject has the following useful methods:
append()
This method can add any value at the end of the collection.
getIterator()
This method simply creates an Iterator object and return so that you can perform
iteration using an Iterator style. This is a very useful method for getting an Iterator
object from any array.
offsetExists()
This method can determine whether the specified offset exists in the collection.
offsetGet()
This method returns the value for specified offset.


Pages:
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76