summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/database/fields.rst
diff options
context:
space:
mode:
authorpurwandi <free6300@gmail.com>2011-10-07 05:35:32 +0200
committerpurwandi <free6300@gmail.com>2011-10-07 05:35:32 +0200
commit550b12dd981c6f7736a957392f6aaf28bdef98dd (patch)
treec01a5460d3b3ad2649aa0f63efa0cf9ada0106df /user_guide_src/source/database/fields.rst
parent15cec71083f3c3085b2e0d719496b195b7c48474 (diff)
parent02db0666a8b4da6a58db0e2f6755143ce1b21971 (diff)
Merge branch 'develop' of https://github.com/EllisLab/CodeIgniter into develop
Diffstat (limited to 'user_guide_src/source/database/fields.rst')
-rw-r--r--user_guide_src/source/database/fields.rst43
1 files changed, 32 insertions, 11 deletions
diff --git a/user_guide_src/source/database/fields.rst b/user_guide_src/source/database/fields.rst
index 07730f5d3..b706ace7d 100644
--- a/user_guide_src/source/database/fields.rst
+++ b/user_guide_src/source/database/fields.rst
@@ -11,12 +11,22 @@ two ways:
1. You can supply the table name and call it from the $this->db->
object::
- $fields = $this->db->list_fields('table_name'); foreach ($fields as $field) {    echo $field; }
+ $fields = $this->db->list_fields('table_name');
+
+ foreach ($fields as $field)
+ {
+ echo $field;
+ }
2. You can gather the field names associated with any query you run by
calling the function from your query result object::
- $query = $this->db->query('SELECT * FROM some_table'); foreach ($query->list_fields() as $field) {    echo $field; }
+ $query = $this->db->query('SELECT * FROM some_table');
+
+ foreach ($query->list_fields() as $field)
+ {
+ echo $field;
+ }
$this->db->field_exists()
==========================
@@ -24,11 +34,14 @@ $this->db->field_exists()
Sometimes it's helpful to know whether a particular field exists before
performing an action. Returns a boolean TRUE/FALSE. Usage example::
- if ($this->db->field_exists('field_name', 'table_name')) {    // some code... }
+ if ($this->db->field_exists('field_name', 'table_name'))
+ {
+ // some code...
+ }
-Note: Replace *field_name* with the name of the column you are looking
-for, and replace *table_name* with the name of the table you are
-looking for.
+.. note:: Replace *field_name* with the name of the column you are looking
+ for, and replace *table_name* with the name of the table you are
+ looking for.
$this->db->field_data()
========================
@@ -38,16 +51,25 @@ Returns an array of objects containing field information.
Sometimes it's helpful to gather the field names or other metadata, like
the column type, max length, etc.
-Note: Not all databases provide meta-data.
+.. note:: Not all databases provide meta-data.
Usage example::
- $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; }
+ $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;
+ }
If you have run a query already you can use the result object instead of
supplying the table name::
- $query = $this->db->query("YOUR QUERY"); $fields = $query->field_data();
+ $query = $this->db->query("YOUR QUERY");
+ $fields = $query->field_data();
The following data is available from this function if supported by your
database:
@@ -55,5 +77,4 @@ database:
- name - column name
- max_length - maximum length of the column
- primary_key - 1 if the column is a primary key
-- type - the type of the column
-
+- type - the type of the column \ No newline at end of file