user_guide_src/source/database/examples.rst
########################### Quick Start: Usage Examples ###########################
The following page contains example code showing how the database class is used. For complete details please read the individual pages describing each function.
.. note:: CodeIgniter doesn't support dots (.) in the table and column names.
Since v4.5.0, database names with dots are supported.
.. contents:: :local: :depth: 2
The following code loads and initializes the database class based on
your :doc:configuration <configuration> settings:
.. literalinclude:: examples/001.php
Once loaded the class is ready to be used as described below.
.. note:: If all your pages require database access you can connect
automatically. See the :doc:Connecting to a Database <connecting> page for details.
.. literalinclude:: examples/002.php
| The above getResult() function returns an array of objects.
| Example: $row->title
.. literalinclude:: examples/003.php
| The above getResultArray() function returns an array of standard array
indexes.
| Example: $row['title']
.. literalinclude:: examples/004.php
The above getRow() function returns an object. Example: $row->name
.. literalinclude:: examples/005.php
The above getRowArray() function returns an array. Example:
$row['name'].
.. literalinclude:: examples/006.php
The :doc:Query Builder <query_builder> gives you a simplified
means of retrieving data:
.. literalinclude:: examples/007.php
The above get() function retrieves all the results from the supplied
table. The :doc:Query Builder <query_builder> class contains a full
complement of functions for working with data.
.. literalinclude:: examples/008.php