blob: 07730f5d320ca30ffdfe17ed4772726c916643e7 [file] [log] [blame]
Derek Jones8ede1a22011-10-05 13:34:52 -05001##########
2Field Data
3##########
4
5$this->db->list_fields()
6=========================
7
8Returns an array containing the field names. This query can be called
9two ways:
10
111. You can supply the table name and call it from the $this->db->
12object::
13
14 $fields = $this->db->list_fields('table_name'); foreach ($fields as $field) {    echo $field; }
15
162. You can gather the field names associated with any query you run by
17calling the function from your query result object::
18
19 $query = $this->db->query('SELECT * FROM some_table'); foreach ($query->list_fields() as $field) {    echo $field; }
20
21$this->db->field_exists()
22==========================
23
24Sometimes it's helpful to know whether a particular field exists before
25performing an action. Returns a boolean TRUE/FALSE. Usage example::
26
27 if ($this->db->field_exists('field_name', 'table_name')) {    // some code... }
28
29Note: Replace *field_name* with the name of the column you are looking
30for, and replace *table_name* with the name of the table you are
31looking for.
32
33$this->db->field_data()
34========================
35
36Returns an array of objects containing field information.
37
38Sometimes it's helpful to gather the field names or other metadata, like
39the column type, max length, etc.
40
41Note: Not all databases provide meta-data.
42
43Usage example::
44
45 $fields = $this->db->field_data('table_name'); foreach ($fields as $field) {    echo $field->name;    echo $field->type;    echo $field->max_length;    echo $field->primary_key; }
46
47If you have run a query already you can use the result object instead of
48supplying the table name::
49
50 $query = $this->db->query("YOUR QUERY"); $fields = $query->field_data();
51
52The following data is available from this function if supported by your
53database:
54
55- name - column name
56- max_length - maximum length of the column
57- primary_key - 1 if the column is a primary key
58- type - the type of the column
59