1 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en">
3 <title>CarbonPHP Documentation
</title>
4 <style type=
"text/css">
11 font-family: "Lucida Sans Unicode", "Lucida Grande";
33 margin: 10px 0 10px 0;
34 list-style-position: inside
;
42 border: 1px dotted
#444;
50 border: 1px solid
#ccc;
61 <h1>Field Meta Data
</h1>
63 <p>These are a set of methods that let you retrieve information about fields within a table.
</p>
67 <h1>$this-
>db-
>list_fields()
</h1>
69 <p>This method returns an array containing the names of the fields in the specified table. There are two ways
70 in which you can call this method.
</p>
74 <p>You can supply the table name and call it from the
<b>$this-
>db
</b> object.
</p>
77 $fields = $this-
>db-
>list_fields('some_table');
<br />
79 foreach ($fields as $field)
<br />
81 echo $field;
<br />
87 <p>You can gather the field names associated with any query that you run.
</p>
90 $query = $this-
>db-
>query('SELECT * FROM `some_table`');
<br />
92 foreach ($query-
>list_fields() as $field)
<br />
94 echo $field;
<br />
101 <div class=
"content">
102 <h1>$this-
>db-
>field_exists()
</h1>
104 <p>This method returns whether a field in a table exists or not.
</p>
106 <div class=
"example">
107 if ($this-
>db-
>field_exists('field_name', 'table_name'))
<br />
109 // Execute some code...
<br />
114 <div class=
"content">
115 <h1>$this-
>db-
>field_data()
</h1>
117 <p>This method returns an array of object containing the information for the specified field. Sometimes
118 it is helpful to gather informatin about field names.
</p>
120 <div class=
"example">
121 $fields = $this-
>db-
>field_data('table_name');
<br />
123 foreach ($fields as $field)
<br />
125 echo $field-
>name;
<br />
126 echo $field-
>type;
<br />
127 echo $field-
>max_length;
<br />
128 echo $field-
>primary_key;
<br />
132 <p>If you have run a query already you can use the result object instead of supplying a table name.
</p>
134 <div class=
"example">
135 $query = $this-
>db-
>query('SQL QUERY');
<br />
136 $fields = $query-
>field_data();
139 <p>You can retrieve the following data about the fields.
</p>
142 <li><b>name
</b> - the name of the column.
</li>
143 <li><b>max_length
</b> - the maximum length of the column.
</li>
144 <li><b>primary_key
</b> - returns
1 if the column is a primary key.
</li>
145 <li><b>type
</b> - returns the data type of the column
</li>