Prev | Current Page 648 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


If the query is intended to return a result set, the optional result_type parameter
specifies how the result set is indexed. By default it will return the set using both associative
and numerical indices (SQLITE_BOTH). You can use SQLITE_ASSOC to return the
set as associative indices, and SQLITE_NUM to return the set using numerical indices.
Finally, the optional &error_msg parameter (available as of PHP 5.1.0) can be used
should you wish to review any SQL syntax error that might occur. Should an error occur,
the error message will be made available by way of a variable of the parameter name.
An example follows:
CHAPTER 22 ?–  SQLITE 575
$sqldb = sqlite_open("corporate.db");
$results = sqlite_query($sqldb, "SELECT * FROM employees",
SQLITE_NUM, &error) OR DIE($error);
while (list($empid, $name) = sqlite_fetch_array($results)) {
echo "Name: $name (Employee ID: $empid)
";
}
sqlite_close($sqldb);
?>
This yields the following results:
Name: Jason Gilmore (Employee ID: 1)
Name: Sam Spade (Employee ID: 2)
Name: Ray Fox (Employee ID: 3)
Keep in mind that sqlite_query() will only execute the query and return a result
set (if one is warranted); it will not output or offer any additional information regarding
the returned data. To obtain such information, you need to pass the result set into
one or several other functions, all of which are introduced in the following sections.


Pages:
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660