db_get_data

mixed db_get_data (string tablename [, mixed id [, mixed col [, string where [, int type [, string idfield [, string orderby]]]]]])

Reads data from a table.

tablename is the name of the table that will be examined. If it is NULL, the function uses the most recently used table (the one used in the last non-NULL function call).
id is a record identifier key or a set of identifiers that may be an array or a CSV string.
col is a string with the name(s) of the columns(s) desired. It may be an array or a CSV string.
where is an optional "WHERE" SQL clause.
type defines the kind of data returned. Accepted values are FETCH_BOTH, FETCH_NUM (the default) and FETCH_ASSOC.
idfield is the name of identifier field (column). Default is "id".
orderby is an optional "ORDER BY" SQL clause.

Keys and columns

The table below summarizes the options for id and col.

id

col

Data returned

integer

null

Array with the whole record id

integer

string

The value of column col of record id

integer

string array

Array with column values in array col of record id

integer array

null

Array of arrays with values from all columns of the id records

integer array

string

Array with the values of column col from the id records

integer array

string array

Two-dimensional array with the values of columns col from the id records

null

null

Array of arrays with the whole table

null

string

Array with values of the col column from the whole table

null

string array

Array of arrays with the values of the columns col from the whole table

Result

The result type specifies which type of data you want to return. There are three possible types:


Example

// Open database

db_open_database("sample.db");

// Read data from user whose identifier is 53

wb_set_text(wb_get_control($mainwin, ID_USER), db_get_data("user", 53));

// Fill up a list box with all user names

wb_set_text(wb_get_control($mainwin, ID_USERS), db_get_data("user", null, "name"));

// Display all users that are over 18 in a ListView

$itemlist = wb_get_control($window, ID_USERLIST);
$fields = array("id","name","phone","address");
$item_data = db_get_data("user", null, $fields, "age > 18");
wb_set_text($itemlist, $fields);
wb_create_items($itemlist, $item_data, true);


See also

Database functions
Database support