blob: b706ace7dd8347f74b2c5075454f03fd6142708c [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
Joseph Wensleyf24f4042011-10-06 22:53:29 -040014 $fields = $this->db->list_fields('table_name');
15
16 foreach ($fields as $field)
17 {
18 echo $field;
19 }
Derek Jones8ede1a22011-10-05 13:34:52 -050020
212. You can gather the field names associated with any query you run by
22calling the function from your query result object::
23
Joseph Wensleyf24f4042011-10-06 22:53:29 -040024 $query = $this->db->query('SELECT * FROM some_table');
25
26 foreach ($query->list_fields() as $field)
27 {
28 echo $field;
29 }
Derek Jones8ede1a22011-10-05 13:34:52 -050030
31$this->db->field_exists()
32==========================
33
34Sometimes it's helpful to know whether a particular field exists before
35performing an action. Returns a boolean TRUE/FALSE. Usage example::
36
Joseph Wensleyf24f4042011-10-06 22:53:29 -040037 if ($this->db->field_exists('field_name', 'table_name'))
38 {
39 // some code...
40 }
Derek Jones8ede1a22011-10-05 13:34:52 -050041
Joseph Wensleyf24f4042011-10-06 22:53:29 -040042.. note:: Replace *field_name* with the name of the column you are looking
43 for, and replace *table_name* with the name of the table you are
44 looking for.
Derek Jones8ede1a22011-10-05 13:34:52 -050045
46$this->db->field_data()
47========================
48
49Returns an array of objects containing field information.
50
51Sometimes it's helpful to gather the field names or other metadata, like
52the column type, max length, etc.
53
Joseph Wensleyf24f4042011-10-06 22:53:29 -040054.. note:: Not all databases provide meta-data.
Derek Jones8ede1a22011-10-05 13:34:52 -050055
56Usage example::
57
Joseph Wensleyf24f4042011-10-06 22:53:29 -040058 $fields = $this->db->field_data('table_name');
59
60 foreach ($fields as $field)
61 {
62 echo $field->name;
63 echo $field->type;
64 echo $field->max_length;
65 echo $field->primary_key;
66 }
Derek Jones8ede1a22011-10-05 13:34:52 -050067
68If you have run a query already you can use the result object instead of
69supplying the table name::
70
Joseph Wensleyf24f4042011-10-06 22:53:29 -040071 $query = $this->db->query("YOUR QUERY");
72 $fields = $query->field_data();
Derek Jones8ede1a22011-10-05 13:34:52 -050073
74The following data is available from this function if supported by your
75database:
76
77- name - column name
78- max_length - maximum length of the column
79- primary_key - 1 if the column is a primary key
Joseph Wensleyf24f4042011-10-06 22:53:29 -040080- type - the type of the column