carbonPHP Initial commit v2.0
[carbonphp.git] / Documentation / database / field_data.html
blob190621da408a79ac81aa31d8835f3926d40ff56c
1 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
2 <head>
3 <title>CarbonPHP Documentation</title>
4 <style type="text/css">
5 * {
6 margin: 0;
7 padding: 0;
10 html {
11 font-family: "Lucida Sans Unicode", "Lucida Grande";
12 font-size: 12px;
15 body {
16 background: #fff;
17 color: #666;
20 h1 {
21 font-size: 15px;
22 font-weight: bold;
23 margin: 0 0 5px 0;
26 h2 {
27 font-size: 13px;
28 font-weight: bold;
29 margin: 5px 0 5px 0;
32 ol, ul {
33 margin: 10px 0 10px 0;
34 list-style-position: inside;
37 p {
38 margin: 5px 0 5px 0;
41 .content {
42 border: 1px dotted #444;
43 margin: 10px;
44 padding: 10px;
45 text-align: justify;
46 width: 700px;
49 .example {
50 border: 1px solid #ccc;
51 background: #eee;
52 margin: 10px;
53 padding: 10px;
54 text-align: left;
56 </style>
57 </head>
59 <body>
60 <div class="content">
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>
64 </div>
66 <div class="content">
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>
72 <ol>
73 <li>
74 <p>You can supply the table name and call it from the <b>$this->db</b> object.</p>
76 <div class="example">
77 $fields = $this->db->list_fields('some_table');<br />
78 <br />
79 foreach ($fields as $field)<br />
80 &#123;<br />
81 &nbsp;&nbsp;&nbsp;&nbsp;echo $field;<br />
82 &#125;
83 </div>
84 </li>
86 <li>
87 <p>You can gather the field names associated with any query that you run.</p>
89 <div class="example">
90 $query = $this->db->query('SELECT * FROM `some_table`');<br />
91 <br />
92 foreach ($query->list_fields() as $field)<br />
93 &#123;<br />
94 &nbsp;&nbsp;&nbsp;&nbsp;echo $field;<br />
95 &#125;
96 </div>
97 </li>
98 </ol>
99 </div>
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 />
108 &#123;<br />
109 &nbsp;&nbsp;&nbsp;&nbsp;// Execute some code...<br />
110 &#125;
111 </div>
112 </div>
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 />
122 <br />
123 foreach ($fields as $field)<br />
124 &#123;<br />
125 &nbsp;&nbsp;&nbsp;&nbsp;echo $field->name;<br />
126 &nbsp;&nbsp;&nbsp;&nbsp;echo $field->type;<br />
127 &nbsp;&nbsp;&nbsp;&nbsp;echo $field->max_length;<br />
128 &nbsp;&nbsp;&nbsp;&nbsp;echo $field->primary_key;<br />
129 &#125;
130 </div>
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();
137 </div>
139 <p>You can retrieve the following data about the fields.</p>
141 <ul>
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>
146 </ul>
147 </div>
148 </body>
150 </html>