sqlite_fetch_bound
Fetches the current row from a result and assigns the column values in variables and then advances to the next row.
Syntax
$sqlite_fetch_bound ( result [, bind_type ] )
|
Parameters
result
The result identifier.
bind_type
The type of the bind. Optional, see remarks for more info.
Return Value
1 on success; Otherwise 0 if there are no more rows available, or $null if there was an error.
Remarks
$sqlite_fetch_bound fetches the next row from the result and assigns the column data in variables specified by $sqlite_fetch_field.bind_type specifies how the values are bound, it can be one of the following: $SQLITE_ALL or $SQLITE_BOUND. $SQLITE_BOUND is default.
If $SQLITE_BOUND is specified, only columns that have been bound with $sqlite_fetch_field are fetched in variables. If $SQLITE_ALL is specified all rows are fetched, even ones that haven't been bound explicitly with $sqlite_fetch_field. In this case the column names are used as variable names. Depending on whether the column type is binary or not, a regular variable or a binary variable will be used.
The bound variables are set as global variables when fetched, because mSQLite has no access to local variables. You should be very careful that you don't override any existing global variables, especially when $SQLITE_ALL is used!
Example
; This code assumes a connection is already established and stored in %db
var %sql = SELECT first_name, last_name, address FROM contacts var %res = $sqlite_query(%db, %sql) if (%res) { ; The first column will be bound to %name sqlite_bind_field %result 1 name ; The third column will be bound to %postal_address sqlite_bind_field %result address first_name ; The second column will be bound automatically to %last_name with $SQLITE_ALL echo -a Fetching results... echo -a - while ($sqlite_fetch_bound(%res, $SQLITE_ALL)) { ; If you used $SQLITE_BOUND, %last_name would not exist because it wasn't bound explicitly with sqlite_bind_field echo -a First name: %name echo -a Last name: %last_name echo -a Address: %postal_address echo -a - } sqlite_free %res } else { echo -a Error executing query: %sqlite_errstr } |