db");
$results = sqlite_query($sqldb,"SELECT name FROM employees WHERE empid < 3");
while ($name = sqlite_fetch_single($results)) {
echo "Employee: $name
";
}
sqlite_close($sqldb);
?>
This returns the following:
Employee: Jason Gilmore
Employee: Sam Spade
Retrieving Result Set Details
You??™ll often want to learn more about a result set than just its contents. Several SQLitespecific
functions are available for determining information such as the returned field
names, the number of fields and rows returned, and the number of rows changed by
the most recent statement. These functions are introduced in this section.
Retrieving Field Names
The sqlite_field_name() function returns the name of the field located at a desired
index offset found in the result set. Its prototype follows:
string sqlite_field_name(resource result, int field_index)
An example follows:
$sqldb = sqlite_open("corporate.db");
$results = sqlite_query($sqldb,"SELECT * FROM employees");
echo "Field name found at offset #0: ".sqlite_field_name($results,0)."
";
echo "Field name found at offset #1: ".sqlite_field_name($results,1)."
";
echo "Field name found at offset #2: ".sqlite_field_name($results,2)."
";
sqlite_close($sqldb);
?>
CHAPTER 22 ?– SQLITE 581
This returns the following:
Field name found at offset #0: empid
Field name found at offset #1: name
Field name found at offset #2: title
As is the case with all numerically indexed arrays, the offset starts at 0, not 1.
Pages:
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666